浏览代码

-lineEdit files

gapchich 13 年之前
父节点
当前提交
2d3e2fcae2
共有 2 个文件被更改,包括 174 次插入0 次删除
  1. 117 0
      LineEditForm.cpp
  2. 57 0
      LineEditForm.h

+ 117 - 0
LineEditForm.cpp

@@ -0,0 +1,117 @@
+/*
+ * LineEditForm.cpp
+ *
+ *  Created on: Oct 6, 2011
+ *      Author: Gapchich Vlad
+ */
+
+#include "LineEditForm.h"
+
+#include <QLineEdit>
+#include <QPushButton>
+#include <QBoxLayout>
+#include <QMessageBox>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QKeyEvent>
+
+LineEditForm::LineEditForm(QWidget *aParent)
+	: QWidget(aParent)
+{
+	//setWindowTitle(tr("Image Description"));
+	purpose_ = NoPurpose;
+
+	layout_v_ = new QVBoxLayout(this);
+	layout_h_ = new QHBoxLayout;
+
+	data_ = new QLineEdit(this);
+	button_ok_ = new QPushButton(this);
+	button_ok_->setText(tr("OK"));
+	button_cancel_ = new QPushButton(this);
+	button_cancel_->setText(tr("Cancel"));
+
+	layout_v_->addWidget(data_);
+	layout_v_->addLayout(layout_h_);
+
+	layout_h_->addWidget(button_ok_);
+	layout_h_->addWidget(button_cancel_);
+
+	connect(
+		button_ok_,
+		SIGNAL(clicked()),
+		this,
+		SLOT(setData())
+		);
+	connect(
+		button_cancel_,
+		SIGNAL(clicked()),
+		this,
+		SLOT(hide())
+		);
+
+	adjustSize();
+	move(QApplication::desktop()->screen()->rect().center() - rect().center());
+}
+
+LineEditForm::~LineEditForm()
+{
+	delete data_;
+	delete button_ok_;
+	delete button_cancel_;
+
+	delete layout_v_;
+}
+
+void
+LineEditForm::setData()
+{
+	if (!data_->text().isEmpty()) {
+		emit dataSet(data_->text());
+		hide();
+	}
+	else
+		QMessageBox::warning(
+			this,
+			tr("Warning!"),
+			tr("Image description is empty"),
+			QMessageBox::Ok,
+			QMessageBox::Cancel
+			);
+}
+
+void
+LineEditForm::setDescription()
+{
+	data_->clear();
+	purpose_ = ImageDescriptionPurpose;
+	setWindowTitle(tr("Image Description"));
+	show();
+}
+
+void
+LineEditForm::setTags()
+{
+	data_->clear();
+	purpose_ = TaggingPurpose;
+	setWindowTitle(tr("Tagging"));
+	show();
+}
+
+FormPurpose
+LineEditForm::purpose()
+{
+	return purpose_;
+}
+
+void
+LineEditForm::keyPressEvent(QKeyEvent *anEvent)
+{
+	if ((Qt::Key_Enter == anEvent->key() ||
+		Qt::Key_Return == anEvent->key())) {
+		setData();
+	}
+}
+
+/*
+ *
+ */

+ 57 - 0
LineEditForm.h

@@ -0,0 +1,57 @@
+/*
+ * ImageDescriptionForm.h
+ *
+ *  Created on: Oct 6, 2011
+ *      Author: Gapchich Vlad
+ */
+
+#ifndef __LINEEDITFORM_H__
+#define __LINEEDITFORM_H__
+
+#include <QWidget>
+
+class QLineEdit;
+class QPushButton;
+class QVBoxLayout;
+class QHBoxLayout;
+class QKeyEvent;
+
+enum FormPurpose {
+	NoPurpose,
+	ImageDescriptionPurpose,
+	TaggingPurpose
+};
+
+class LineEditForm : public QWidget {
+	Q_OBJECT
+protected:
+	void keyPressEvent(QKeyEvent *anEvent);
+public:
+	LineEditForm(QWidget *aParent = 0);
+	virtual ~LineEditForm();
+	FormPurpose purpose();
+
+public slots:
+	void setData();
+	void setDescription();
+	void setTags();
+
+signals:
+	void dataSet(QString aData);
+
+private:
+	QLineEdit *data_;
+	QPushButton *button_ok_;
+	QPushButton *button_cancel_;
+
+	QVBoxLayout *layout_v_;
+	QHBoxLayout *layout_h_;
+
+	FormPurpose purpose_;
+};
+
+#endif /* __LINEEDITFORM_H__ */
+
+/*
+ *
+ */