00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011
00012
00013
00014 #include "PSQt/allinone.h"
00015 #include "PSQt/custombutton.h"
00016 #include "PSQt/lines.h"
00017 #include "PSQt/donut.h"
00018
00019
00020 namespace PSQt {
00021
00022
00023
00024 MyWidget::MyWidget( QWidget *parent )
00025 {
00026
00027
00028 this -> setFrame();
00029
00030 QPalette* palette1 = new QPalette(); palette1->setColor(QPalette::Base,Qt::darkCyan);
00031 QPalette* palette2 = new QPalette(); palette2->setColor(QPalette::Base,Qt::yellow);
00032 QPalette* palette3 = new QPalette(); palette3->setColor(QPalette::Base,Qt::red);
00033
00034 QLabel* label = new QLabel("Test of QLabel");
00035 m_line_edit = new QLineEdit("Test of QLineEdit");
00036 QTextEdit* text_edit = new QTextEdit("Test of QTextEdit");
00037 QPushButton* button = new QPushButton( "Test of QPushButton", this );
00038 QLCDNumber* lcd = new QLCDNumber( this );
00039 QSlider* slider = new QSlider( Qt::Horizontal, this );
00040
00041 CustomButton* custom = new CustomButton(this);
00042 custom->setMinimumHeight(40);
00043
00044 QRadioButton* radio1 = new QRadioButton("Test of QRadioButton 1");
00045 QRadioButton* radio2 = new QRadioButton("Test of QRadioButton 2");
00046 QButtonGroup* radioGroup = new QButtonGroup();
00047
00048 QComboBox* comboBox = new QComboBox();
00049 comboBox->addItem(tr("Solid"), Qt::SolidLine);
00050 comboBox->addItem(tr("Dash"), Qt::DashLine);
00051 comboBox->addItem(tr("Dot"), Qt::DotLine);
00052 comboBox->addItem(tr("None"), Qt::NoPen);
00053
00054 QCheckBox* checkBox = new QCheckBox(tr("QCh&eckBox"));
00055 checkBox->setChecked(true);
00056
00057 QSpinBox* spinBox = new QSpinBox();
00058 spinBox->setRange(0, 20);
00059 spinBox->setSpecialValueText(tr("0 (cosmetic pen)"));
00060
00061 radioGroup->addButton(radio1);
00062 radioGroup->addButton(radio2);
00063 radio1->setChecked(true);
00064
00065 text_edit->setFixedSize(500,50);
00066 text_edit->setPalette(*palette1);
00067 m_line_edit->setPalette(*palette2);
00068
00069 button ->setStyleSheet("background-color: rgb(255, 0, 0); color: rgb(255, 255, 255)");
00070 text_edit->setStyleSheet("background-color: rgb(0, 255, 0); color: rgb(100, 100, 100)");
00071
00072 PSQt::Lines* lines = new PSQt::Lines();
00073 lines->setMinimumHeight(140);
00074
00075
00076 PSQt::Donut* donut = new PSQt::Donut();
00077 donut->setMinimumHeight(240);
00078
00079 connect( slider, SIGNAL( valueChanged(int)), lcd, SLOT(display(int)) );
00080 connect( button, SIGNAL( clicked() ), this, SLOT( onButton()) );
00081 connect( text_edit, SIGNAL( textChanged() ), this, SLOT( onTextEdit()) );
00082 connect( m_line_edit, SIGNAL( editingFinished() ), this, SLOT( onLineEdit()) );
00083 connect( radio1, SIGNAL( clicked() ), this, SLOT( onRadio1()) );
00084 connect( radio2, SIGNAL( clicked() ), this, SLOT( onRadio2()) );
00085 connect( comboBox, SIGNAL( activated(int)), this, SLOT(onComboBox()));
00086 connect( checkBox, SIGNAL( toggled(bool)), this, SLOT(onCheckBox()));
00087 connect( spinBox, SIGNAL( valueChanged(int)), this, SLOT(onSpinBox()));
00088 connect( custom, SIGNAL( clicked() ), this, SLOT( onCustomButton()) );
00089
00090 QVBoxLayout *vbox = new QVBoxLayout();
00091
00092 vbox -> addWidget(label);
00093 vbox -> addWidget(button);
00094 vbox -> addWidget(m_line_edit);
00095 vbox -> addWidget(text_edit);
00096 vbox -> addWidget(radio1);
00097 vbox -> addWidget(radio2);
00098 vbox -> addWidget(lcd);
00099 vbox -> addWidget(slider);
00100 vbox -> addWidget(comboBox);
00101 vbox -> addWidget(checkBox);
00102 vbox -> addWidget(spinBox);
00103 vbox -> addWidget(custom);
00104 vbox -> addWidget(lines);
00105 vbox -> addWidget(donut);
00106
00107 this -> setLayout(vbox);
00108
00109 setWindowTitle(tr("Basic Drawing"));
00110 this -> move(100,50);
00111 }
00112
00113
00114
00115 void MyWidget::setFrame()
00116 {
00117 m_frame = new QFrame(this);
00118 m_frame -> setFrameStyle ( QFrame::Box | QFrame::Sunken);
00119
00120
00121 m_frame -> setLineWidth(0);
00122 m_frame -> setMidLineWidth(1);
00123 m_frame -> setCursor(Qt::SizeAllCursor);
00124 m_frame -> setStyleSheet("background-color: rgb(0, 255, 255); color: rgb(255, 255, 100)");
00125 }
00126
00127
00128
00129 void MyWidget::resizeEvent(QResizeEvent *event)
00130 {
00131
00132 m_frame->setGeometry(0, 0, event->size().width(), event->size().height());
00133 setWindowTitle("Window is resized");
00134 }
00135
00136
00137
00138 void MyWidget::closeEvent(QCloseEvent *event)
00139 {
00140 QWidget::closeEvent(event);
00141 std::cout << "MyWidget::closeEvent type = " << event -> type() << std::endl;
00142 }
00143
00144
00145
00146 void MyWidget::moveEvent(QMoveEvent *event)
00147 {
00148 int x = event->pos().x();
00149 int y = event->pos().y();
00150 QString text = QString::number(x) + "," + QString::number(y);
00151 setWindowTitle(text);
00152 }
00153
00154
00155
00156 void MyWidget::mousePressEvent (QMouseEvent *event)
00157 {
00158 int x = event->pos().x();
00159 int y = event->pos().y();
00160 QString text = "mousePressEvent: " + QString::number(x) + "," + QString::number(y);
00161 std::cout << text.toStdString() << std::endl;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 void MyWidget::onButton()
00171 {
00172 std::cout << "Button is clicked\n";
00173 }
00174
00175
00176
00177 void MyWidget::onCustomButton()
00178 {
00179 std::cout << "Custom button is clicked\n";
00180 }
00181
00182
00183
00184 void MyWidget::onLineWindow()
00185 {
00186 std::cout << "Line window is clicked\n";
00187 }
00188
00189
00190
00191 void MyWidget::onDonutWindow()
00192 {
00193 std::cout << "Donut window is clicked\n";
00194 }
00195
00196
00197
00198 void MyWidget::onRadio1()
00199 {
00200 std::cout << "Radio1 is clicked\n";
00201 }
00202
00203
00204
00205 void MyWidget::onRadio2()
00206 {
00207 std::cout << "Radio2 is clicked\n";
00208 }
00209
00210
00211
00212 void MyWidget::onComboBox()
00213 {
00214 std::cout << "Combo box is changed\n";
00215 }
00216
00217
00218
00219 void MyWidget::onSpinBox()
00220 {
00221 std::cout << "Spin box is changed\n";
00222 }
00223
00224
00225
00226 void MyWidget::onCheckBox()
00227 {
00228 std::cout << "Check box is changed\n";
00229 }
00230
00231
00232
00233 void MyWidget::onTextEdit()
00234 {
00235 std::cout << "Text is changed\n";
00236 }
00237
00238
00239
00240 void MyWidget::onLineEdit()
00241 {
00242 QString qstring = m_line_edit -> text();
00243 std::cout << "Line is changed to:" << qstring.toStdString() << std::endl;
00244 }
00245
00246
00247
00248 }
00249
00250