Oppgave1mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QApplication>
#include <QPushButton>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QWidget>
#include "vistekst.h"
class MainWindow : public QDialog
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QPushButton* btnDontPush;
QLineEdit* lineEdit;
private slots:
void openNewWindow();
};
#endif // MAINWINDOW_H
vistekst.h
#define MAINWINDOW_H
#include <QApplication>
#include <QPushButton>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QWidget>
#include "vistekst.h"
class MainWindow : public QDialog
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QPushButton* btnDontPush;
QLineEdit* lineEdit;
private slots:
void openNewWindow();
};
#endif // MAINWINDOW_H
#ifndef VISTEKST_H
#define VISTEKST_H
#include <QDialog>
#include <QString>
#include <QLabel>
#include <QHBoxLayout>
class VisTekst : public QDialog
{
Q_OBJECT
public:
explicit VisTekst(const QString &theText, QWidget *parent = 0 );
signals:
public slots:
};
#endif // VISTEKST_H
mainwindow.cpp
#define VISTEKST_H
#include <QDialog>
#include <QString>
#include <QLabel>
#include <QHBoxLayout>
class VisTekst : public QDialog
{
Q_OBJECT
public:
explicit VisTekst(const QString &theText, QWidget *parent = 0 );
signals:
public slots:
};
#endif // VISTEKST_H
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QDialog(parent) {
setWindowTitle( "nice" );
lineEdit = new QLineEdit;
btnDontPush = new QPushButton( tr( "Ikke trykk" ));
QObject::connect( btnDontPush, SIGNAL( clicked() ),
this, SLOT( openNewWindow() ) );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( lineEdit );
layout->addWidget( btnDontPush );
setLayout( layout );
}
void MainWindow::openNewWindow() {
VisTekst* diag = new VisTekst( lineEdit->text(), this );
diag->show();
lineEdit->setText("");
}
MainWindow::~MainWindow()
{
delete lineEdit;
delete btnDontPush;
}
vistekst.cpp
MainWindow::MainWindow(QWidget *parent) : QDialog(parent) {
setWindowTitle( "nice" );
lineEdit = new QLineEdit;
btnDontPush = new QPushButton( tr( "Ikke trykk" ));
QObject::connect( btnDontPush, SIGNAL( clicked() ),
this, SLOT( openNewWindow() ) );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( lineEdit );
layout->addWidget( btnDontPush );
setLayout( layout );
}
void MainWindow::openNewWindow() {
VisTekst* diag = new VisTekst( lineEdit->text(), this );
diag->show();
lineEdit->setText("");
}
MainWindow::~MainWindow()
{
delete lineEdit;
delete btnDontPush;
}
#include "vistekst.h"
VisTekst::VisTekst( const QString &theText, QWidget *parent) :
QDialog( parent )
{
QLabel* label = new QLabel( theText );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( label );
setLayout( layout );
}
main.cpp
VisTekst::VisTekst( const QString &theText, QWidget *parent) :
QDialog( parent )
{
QLabel* label = new QLabel( theText );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( label );
setLayout( layout );
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Skjermskudd #1
Skjermskudd #2
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Oppgave2mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QDialog>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include "skrivtekst.h"
class MainWindow : public QDialog
{
Q_OBJECT
public:
explicit MainWindow( QWidget* parent = 0);
~MainWindow();
private:
QLabel* label;
QPushButton* btnDontPress;
SkrivTekst* diag;
private slots:
void openNewWindow();
void deleteNewWindow();
};
#endif // MAINWINDOW_H
skrivtekst.h
#define MAINWINDOW_H
#include <QDialog>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include "skrivtekst.h"
class MainWindow : public QDialog
{
Q_OBJECT
public:
explicit MainWindow( QWidget* parent = 0);
~MainWindow();
private:
QLabel* label;
QPushButton* btnDontPress;
SkrivTekst* diag;
private slots:
void openNewWindow();
void deleteNewWindow();
};
#endif // MAINWINDOW_H
#ifndef SKRIVTEKST_H
#define SKRIVTEKST_H
#include <QDialog>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
class SkrivTekst : public QDialog
{
Q_OBJECT
public:
explicit SkrivTekst( QLabel* thelabel, QWidget* parent = 0 );
~SkrivTekst();
private:
QLineEdit* lineEdit;
QPushButton* btnClose;
QHBoxLayout* layout;
QLabel* label;
private slots:
void onClose();
};
#endif // SKRIVTEKST_H
mainwindow.cpp
#define SKRIVTEKST_H
#include <QDialog>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
class SkrivTekst : public QDialog
{
Q_OBJECT
public:
explicit SkrivTekst( QLabel* thelabel, QWidget* parent = 0 );
~SkrivTekst();
private:
QLineEdit* lineEdit;
QPushButton* btnClose;
QHBoxLayout* layout;
QLabel* label;
private slots:
void onClose();
};
#endif // SKRIVTEKST_H
#include "mainwindow.h"
MainWindow::MainWindow( QWidget* parent ) : QDialog( parent )
{
QHBoxLayout* layout = new QHBoxLayout;
label = new QLabel("");
layout->addWidget( label );
btnDontPress = new QPushButton( tr( "Trykk for å endre labelen" ) );
layout->addWidget( btnDontPress );
setLayout( layout );
diag = new SkrivTekst(label, this);
QObject::connect( btnDontPress, SIGNAL( clicked() ),
this, SLOT( openNewWindow() ) );
/*
QObject::connect( diag, SIGNAL( onClose() ),
this, SLOT( deleteNewWindow() ) );
*/
}
MainWindow::~MainWindow() {
delete label;
delete btnDontPress;
}
void MainWindow::deleteNewWindow() {
delete diag;
}
void MainWindow::openNewWindow() {
diag->show();
}
skrivtekst.cpp
MainWindow::MainWindow( QWidget* parent ) : QDialog( parent )
{
QHBoxLayout* layout = new QHBoxLayout;
label = new QLabel("");
layout->addWidget( label );
btnDontPress = new QPushButton( tr( "Trykk for å endre labelen" ) );
layout->addWidget( btnDontPress );
setLayout( layout );
diag = new SkrivTekst(label, this);
QObject::connect( btnDontPress, SIGNAL( clicked() ),
this, SLOT( openNewWindow() ) );
/*
QObject::connect( diag, SIGNAL( onClose() ),
this, SLOT( deleteNewWindow() ) );
*/
}
MainWindow::~MainWindow() {
delete label;
delete btnDontPress;
}
void MainWindow::deleteNewWindow() {
delete diag;
}
void MainWindow::openNewWindow() {
diag->show();
}
#include "skrivtekst.h"
SkrivTekst::SkrivTekst( QLabel* thelabel, QWidget* parent )
: QDialog( parent ), label( thelabel ) {
layout = new QHBoxLayout;
lineEdit = new QLineEdit;
layout->addWidget( lineEdit );
btnClose = new QPushButton( "Lukk" );
layout->addWidget( btnClose );
setLayout( layout );
QObject::connect( btnClose, SIGNAL( clicked() ),
this, SLOT( onClose() ) );
}
void SkrivTekst::onClose() {
label->setText( lineEdit->text() );
this->close();
}
SkrivTekst::~SkrivTekst() {
delete lineEdit;
delete btnClose;
delete layout;
delete label;
}
main.cpp
SkrivTekst::SkrivTekst( QLabel* thelabel, QWidget* parent )
: QDialog( parent ), label( thelabel ) {
layout = new QHBoxLayout;
lineEdit = new QLineEdit;
layout->addWidget( lineEdit );
btnClose = new QPushButton( "Lukk" );
layout->addWidget( btnClose );
setLayout( layout );
QObject::connect( btnClose, SIGNAL( clicked() ),
this, SLOT( onClose() ) );
}
void SkrivTekst::onClose() {
label->setText( lineEdit->text() );
this->close();
}
SkrivTekst::~SkrivTekst() {
delete lineEdit;
delete btnClose;
delete layout;
delete label;
}
#include <QApplication>
#include "mainwindow.h"
int main( int argc, char* argv[] )
{
QApplication app( argc, argv);
MainWindow m;
m.show();
return app.exec();
}
Skjermskudd #1
Skjermskudd #2
Skjermskudd #3
#include "mainwindow.h"
int main( int argc, char* argv[] )
{
QApplication app( argc, argv);
MainWindow m;
m.show();
return app.exec();
}
Oppgave3avtale.h
#ifndef AVTALE_H
#define AVTALE_H
#include <QString>
class Avtale
{
public:
Avtale( QString atid,
QString ahvem,
QString ahvor,
QString atype,
QString abeskrivelse )
: tid( atid), hvem( ahvem ), hvor( ahvor ), type( atype ), beskrivelse( abeskrivelse ) { }
Avtale();
QString getTid() { return tid; }
QString getHvem() { return hvem; }
QString getHvor() { return hvor; }
QString getType() { return type; }
QString getBeskrivelse() { return beskrivelse; }
private:
QString tid, hvem, hvor, type, beskrivelse;
};
#endif // AVTALE_H
leggtilavtale.h
#define AVTALE_H
#include <QString>
class Avtale
{
public:
Avtale( QString atid,
QString ahvem,
QString ahvor,
QString atype,
QString abeskrivelse )
: tid( atid), hvem( ahvem ), hvor( ahvor ), type( atype ), beskrivelse( abeskrivelse ) { }
Avtale();
QString getTid() { return tid; }
QString getHvem() { return hvem; }
QString getHvor() { return hvor; }
QString getType() { return type; }
QString getBeskrivelse() { return beskrivelse; }
private:
QString tid, hvem, hvor, type, beskrivelse;
};
#endif // AVTALE_H
#ifndef LEGGTILAVTALE_H
#define LEGGTILAVTALE_H
//#include <QtGui>
#include <QObject>
#include <QDialog>
#include <QString>
#include <QDateTimeEdit>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include "visavtale.h"
#include "avtale.h"
class LeggTilAvtale : public QDialog
{
Q_OBJECT
public:
LeggTilAvtale( QWidget* parent = 0);
~LeggTilAvtale();
private:
QDateTimeEdit* dteTid;
QLineEdit* leHvem;
QLineEdit* leHvor;
QComboBox* cbType;
QTextEdit* txtBeskrivelse;
Avtale* avtale;
private slots:
void avtaleModified();
void visAvtale();
};
#endif // LEGGTILAVTALE_H
visavtale.h
#define LEGGTILAVTALE_H
//#include <QtGui>
#include <QObject>
#include <QDialog>
#include <QString>
#include <QDateTimeEdit>
#include <QLineEdit>
#include <QComboBox>
#include <QTextEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include "visavtale.h"
#include "avtale.h"
class LeggTilAvtale : public QDialog
{
Q_OBJECT
public:
LeggTilAvtale( QWidget* parent = 0);
~LeggTilAvtale();
private:
QDateTimeEdit* dteTid;
QLineEdit* leHvem;
QLineEdit* leHvor;
QComboBox* cbType;
QTextEdit* txtBeskrivelse;
Avtale* avtale;
private slots:
void avtaleModified();
void visAvtale();
};
#endif // LEGGTILAVTALE_H
#ifndef VISAVTALE_H
#define VISAVTALE_H
#include <QObject>
#include <QDialog>
#include <QLabel>
#include <QGridLayout>
#include "avtale.h"
class VisAvtale : public QDialog
{
Q_OBJECT
public:
VisAvtale( Avtale* avtale, QWidget* parent = 0 );
};
#endif // VISAVTALE_H
avtale.cpp
#define VISAVTALE_H
#include <QObject>
#include <QDialog>
#include <QLabel>
#include <QGridLayout>
#include "avtale.h"
class VisAvtale : public QDialog
{
Q_OBJECT
public:
VisAvtale( Avtale* avtale, QWidget* parent = 0 );
};
#endif // VISAVTALE_H
#include "avtale.h"
Avtale::Avtale()
{
}
leggtilavtale.cpp
Avtale::Avtale()
{
}
#include "leggtilavtale.h"
LeggTilAvtale::LeggTilAvtale( QWidget* parent ) : QDialog( parent )
{
QVBoxLayout* mainLayout = new QVBoxLayout;
QHBoxLayout* row1 = new QHBoxLayout;
QLabel* lblTid = new QLabel( tr("&Tid:"));
dteTid = new QDateTimeEdit;
lblTid->setBuddy( dteTid);
row1->addWidget( lblTid );
row1->addWidget( dteTid, 1, Qt::AlignRight );
mainLayout->addLayout( row1 );
QHBoxLayout* row2 = new QHBoxLayout;
QLabel* lblHvem = new QLabel( tr( "&Hvem:"));
leHvem = new QLineEdit();
lblHvem->setBuddy( leHvem );
row2->addWidget( lblHvem );
row2->addWidget( leHvem, 1, Qt::AlignRight );
mainLayout->addLayout( row2 );
QHBoxLayout* row3 = new QHBoxLayout;
QLabel* lblHvor = new QLabel( tr( "&Hvor:" ) );
leHvor = new QLineEdit;
lblHvor->setBuddy( leHvor );
row3->addWidget( lblHvor );
row3->addWidget( leHvor, 1, Qt::AlignRight );
mainLayout->addLayout( row3 );
QHBoxLayout* row4 = new QHBoxLayout;
QLabel* lblType = new QLabel( tr( "T&ype:" ) );
cbType = new QComboBox;
cbType->setEditable( true );
lblType->setBuddy( cbType );
row4->addWidget( lblType );
row4->addWidget( cbType, 1, Qt::AlignRight );
mainLayout->addLayout( row4 );
QVBoxLayout* row5 = new QVBoxLayout;
QLabel* lblBeskrivelse = new QLabel( tr( "&Beskrivelse: " ) );
txtBeskrivelse = new QTextEdit;
txtBeskrivelse->setFixedHeight(80);
lblBeskrivelse->setBuddy( txtBeskrivelse );
row5->addWidget( lblBeskrivelse );
row5->addWidget( txtBeskrivelse );
mainLayout->addLayout( row5 );
setWindowTitle("SDS");
QHBoxLayout* row6 = new QHBoxLayout;
QPushButton* btnOK = new QPushButton("OK");
row6->addWidget( btnOK );
mainLayout->addLayout( row6 );
setLayout( mainLayout );
QObject::connect( btnOK, SIGNAL( clicked() ),
this, SLOT( visAvtale() ));
}
void LeggTilAvtale::avtaleModified() {
//delete avtale;
avtale = new Avtale( dteTid->text(),
leHvem->text(),
leHvor->text(),
cbType->currentText(),
txtBeskrivelse->toPlainText()
);
}
void LeggTilAvtale::visAvtale() {
avtaleModified();
VisAvtale* diagVisAvtale = new VisAvtale( avtale );
diagVisAvtale->show();
}
LeggTilAvtale::~LeggTilAvtale() {
delete dteTid;
delete leHvem;
delete leHvor;
delete cbType;
delete txtBeskrivelse;
delete avtale;
}
visavtale.cpp
LeggTilAvtale::LeggTilAvtale( QWidget* parent ) : QDialog( parent )
{
QVBoxLayout* mainLayout = new QVBoxLayout;
QHBoxLayout* row1 = new QHBoxLayout;
QLabel* lblTid = new QLabel( tr("&Tid:"));
dteTid = new QDateTimeEdit;
lblTid->setBuddy( dteTid);
row1->addWidget( lblTid );
row1->addWidget( dteTid, 1, Qt::AlignRight );
mainLayout->addLayout( row1 );
QHBoxLayout* row2 = new QHBoxLayout;
QLabel* lblHvem = new QLabel( tr( "&Hvem:"));
leHvem = new QLineEdit();
lblHvem->setBuddy( leHvem );
row2->addWidget( lblHvem );
row2->addWidget( leHvem, 1, Qt::AlignRight );
mainLayout->addLayout( row2 );
QHBoxLayout* row3 = new QHBoxLayout;
QLabel* lblHvor = new QLabel( tr( "&Hvor:" ) );
leHvor = new QLineEdit;
lblHvor->setBuddy( leHvor );
row3->addWidget( lblHvor );
row3->addWidget( leHvor, 1, Qt::AlignRight );
mainLayout->addLayout( row3 );
QHBoxLayout* row4 = new QHBoxLayout;
QLabel* lblType = new QLabel( tr( "T&ype:" ) );
cbType = new QComboBox;
cbType->setEditable( true );
lblType->setBuddy( cbType );
row4->addWidget( lblType );
row4->addWidget( cbType, 1, Qt::AlignRight );
mainLayout->addLayout( row4 );
QVBoxLayout* row5 = new QVBoxLayout;
QLabel* lblBeskrivelse = new QLabel( tr( "&Beskrivelse: " ) );
txtBeskrivelse = new QTextEdit;
txtBeskrivelse->setFixedHeight(80);
lblBeskrivelse->setBuddy( txtBeskrivelse );
row5->addWidget( lblBeskrivelse );
row5->addWidget( txtBeskrivelse );
mainLayout->addLayout( row5 );
setWindowTitle("SDS");
QHBoxLayout* row6 = new QHBoxLayout;
QPushButton* btnOK = new QPushButton("OK");
row6->addWidget( btnOK );
mainLayout->addLayout( row6 );
setLayout( mainLayout );
QObject::connect( btnOK, SIGNAL( clicked() ),
this, SLOT( visAvtale() ));
}
void LeggTilAvtale::avtaleModified() {
//delete avtale;
avtale = new Avtale( dteTid->text(),
leHvem->text(),
leHvor->text(),
cbType->currentText(),
txtBeskrivelse->toPlainText()
);
}
void LeggTilAvtale::visAvtale() {
avtaleModified();
VisAvtale* diagVisAvtale = new VisAvtale( avtale );
diagVisAvtale->show();
}
LeggTilAvtale::~LeggTilAvtale() {
delete dteTid;
delete leHvem;
delete leHvor;
delete cbType;
delete txtBeskrivelse;
delete avtale;
}
#include "visavtale.h"
VisAvtale::VisAvtale( Avtale* avtale, QWidget* parent )
{
QGridLayout* mainLayout = new QGridLayout;
QLabel* lblTid = new QLabel( tr( "Tid:" ) );
mainLayout->addWidget( lblTid, 0, 0 );
QLabel* lblTidV = new QLabel( avtale->getTid() );
mainLayout->addWidget( lblTidV, 0,1);
QLabel* lblHvem = new QLabel( tr( "Hvor:" ) );
mainLayout->addWidget( lblHvem, 1, 0 );
QLabel* lblHvemV = new QLabel( avtale->getHvem() );
mainLayout->addWidget( lblHvemV, 1, 1 );
QLabel* lblHvor = new QLabel( tr( "Hvor:" ) );
mainLayout->addWidget( lblHvor, 2, 0 );
QLabel* lblHvorV = new QLabel( avtale->getHvor() );
mainLayout->addWidget( lblHvorV, 2, 1 );
QLabel* lblType = new QLabel( tr( "Type:" ) );
mainLayout->addWidget( lblType, 3, 0 );
QLabel* lblTypeV = new QLabel( avtale->getType() );
mainLayout->addWidget( lblTypeV, 3, 1 );
QLabel* lblBeskrivelse = new QLabel( tr( "Beskrivelse:" ) );
mainLayout->addWidget( lblBeskrivelse, 4, 0 );
QLabel* lblBeskrivelseV = new QLabel( avtale->getBeskrivelse() );
mainLayout->addWidget( lblBeskrivelseV, 4, 1 );
setLayout( mainLayout );
}
main.cpp
VisAvtale::VisAvtale( Avtale* avtale, QWidget* parent )
{
QGridLayout* mainLayout = new QGridLayout;
QLabel* lblTid = new QLabel( tr( "Tid:" ) );
mainLayout->addWidget( lblTid, 0, 0 );
QLabel* lblTidV = new QLabel( avtale->getTid() );
mainLayout->addWidget( lblTidV, 0,1);
QLabel* lblHvem = new QLabel( tr( "Hvor:" ) );
mainLayout->addWidget( lblHvem, 1, 0 );
QLabel* lblHvemV = new QLabel( avtale->getHvem() );
mainLayout->addWidget( lblHvemV, 1, 1 );
QLabel* lblHvor = new QLabel( tr( "Hvor:" ) );
mainLayout->addWidget( lblHvor, 2, 0 );
QLabel* lblHvorV = new QLabel( avtale->getHvor() );
mainLayout->addWidget( lblHvorV, 2, 1 );
QLabel* lblType = new QLabel( tr( "Type:" ) );
mainLayout->addWidget( lblType, 3, 0 );
QLabel* lblTypeV = new QLabel( avtale->getType() );
mainLayout->addWidget( lblTypeV, 3, 1 );
QLabel* lblBeskrivelse = new QLabel( tr( "Beskrivelse:" ) );
mainLayout->addWidget( lblBeskrivelse, 4, 0 );
QLabel* lblBeskrivelseV = new QLabel( avtale->getBeskrivelse() );
mainLayout->addWidget( lblBeskrivelseV, 4, 1 );
setLayout( mainLayout );
}
#include <QApplication>
#include "leggtilavtale.h"
int main( int argc, char* argv[] ) {
QApplication app( argc, argv);
LeggTilAvtale a;
a.show();
return app.exec();
}
Skjermskudd #1
Skjermskudd #2
#include "leggtilavtale.h"
int main( int argc, char* argv[] ) {
QApplication app( argc, argv);
LeggTilAvtale a;
a.show();
return app.exec();
}