16,212
社区成员
发帖
与我相关
我的任务
分享
#ifndef CREATENODEINFORMATION_H_
#define CREATENODEINFORMATION_H_
#include <QDialog>
#include "node.h"
class CreateNodeInformation: public QDialog {
public:
CreateNodeInformation(Node* newNode, QWidget* parent=0);
virtual ~CreateNodeInformation();
private slots:
void confirm();
private:
QLabel *label;
QLineEdit *lineEdit;
QPushButton *okButton;
QPushButton *cancelButton;
Node* node;
};
#endif /* CREATENODEINFORMATION_H_ */
#include <QtGUI>
#include "createnodeinformation.h"
CreateNodeInformation::CreateNodeInformation(Node* newNode, QWidget* parent) {
node = newNode;
label = new QLabel("Please input your text");
lineEdit = new QLineEdit;
node->setText("new Node");
lineEdit->setText(node->text());
okButton = new QPushButton("OK", this);
cancelButton = new QPushButton("CANCEL", this);
connect(okButton, SIGNAL(clicked()), this, SLOT(confirm()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(okButton);
rightLayout->addWidget(cancelButton);
rightLayout->addStretch();
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(("Create New Node"));
setFixedHeight(sizeHint().height());
}
CreateNodeInformation::~CreateNodeInformation() {
node = NULL;
}
void CreateNodeInformation::confirm(){
node->setText(lineEdit->text());
QDialog::accept();
}