Advertisement
TShiva

third_project

Jan 31st, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cpp
  2.  
  3. #include <QtGui>
  4. #include <QLabel>
  5. #include <QCheckBox>
  6. #include <QPushButton>
  7. #include "finddialog.h"
  8. #include <QtWidgets/QHBoxLayout>
  9.  
  10. FindDialog::FindDialog(QWidget *parent) : QDialog(parent) {
  11.  
  12.     label = new QLabel(tr("Find &what:"));
  13.     lineEdit = new QLineEdit;
  14.     label->setBuddy(lineEdit);
  15.    
  16.     caseCheckBox = new QCheckBox(tr("Match &case"));
  17.     backwardChechBox = new QCheckBox(tr("Search backward"));
  18.  
  19.     findButton = new QPushButton(tr("&Find"));
  20.     findButton->setDefault(true);
  21.     findButton->setEnabled(false);
  22.  
  23.     closeButton = new QPushButton(tr("Close"));
  24.  
  25.  
  26.     connect(lineEdit,SIGNAL(textChanged(const QString &)),
  27.             this,SLOT(enableFindButton(const QString &)));
  28.  
  29.     connect(lineEdit,SIGNAL(textChanged(const QString &)),this, SLOT(enableFindButton(const QString &)));
  30.     connect(findButton, SIGNAL(clicked()),this, SLOT(findClicked()));
  31.     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
  32.  
  33.     QHBoxLayout* topLeftLayout = new QHBoxLayout;
  34.     topLeftLayout->addWidget(label);
  35.     topLeftLayout->addWidget(lineEdit);
  36.  
  37.     QVBoxLayout* leftLayout = new QVBoxLayout;
  38.     leftLayout->addLayout(topLeftLayout);
  39.     leftLayout->addWidget(caseCheckBox);
  40.     leftLayout->addWidget(backwardChechBox);
  41.  
  42.     QVBoxLayout* rightLayout = new QVBoxLayout;
  43.     rightLayout->addWidget(findButton);
  44.     rightLayout->addWidget(closeButton);
  45.     rightLayout->addStretch();
  46.  
  47.     QHBoxLayout *mainLayout = new QHBoxLayout;
  48.     mainLayout->addLayout(leftLayout);
  49.     mainLayout->addLayout(rightLayout);
  50.     setLayout(mainLayout);
  51.     setWindowTitle(tr("Find"));
  52.     setFixedHeight(sizeHint().height());
  53. }
  54.  
  55. void FindDialog::findClicked() {
  56.     QString text = lineEdit->text();
  57.     Qt::CaseSensitivity  cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
  58.  
  59.     if(backwardChechBox->isChecked()){
  60.         emit findPrev(text, cs);
  61.     } else{
  62.        emit findNext(text,cs);
  63.     }
  64. }
  65.  
  66. void FindDialog::enableFindButton(const QString &text) {
  67.     findButton->setEnabled(!text.isEmpty());
  68. }
  69.  
  70. --------
  71. h
  72.  
  73. #ifndef SECOND_PROGECT_FINDDIALOG_H
  74. #define SECOND_PROGECT_FINDDIALOG_H
  75.  
  76. #include <QDialog>
  77. #include <QLabel>
  78. #include <QCheckBox>
  79. #include <QLineEdit>
  80. #include <QPushButton>
  81.  
  82. class FindDialog : public QDialog{
  83. Q_OBJECT
  84. public:
  85.     FindDialog(QWidget *parent=0);
  86. signals:
  87.     void findNext(const QString &str, Qt::CaseSensitivity cs);
  88.     void findPrev(const QString &str, Qt::CaseSensitivity cs);
  89.  
  90. private slots:
  91.     void findClicked();
  92.     void enableFindButton(const QString &text);
  93.  
  94. private:
  95.     QLabel* label;
  96.     QLineEdit* lineEdit;
  97.     QCheckBox* caseCheckBox;
  98.     QCheckBox* backwardChechBox;
  99.     QPushButton* findButton;
  100.     QPushButton* closeButton;
  101. };
  102.  
  103. #endif
  104.  
  105.  
  106. ----
  107. main
  108.  
  109.  
  110. #include <QApplication>
  111. #include "finddialog.h"
  112.  
  113. int main(int argc,char* argv[]) {
  114.  
  115.     QApplication app(argc,argv);
  116.     FindDialog* dialog = new FindDialog;
  117.     dialog->show();
  118.     return  app.exec();
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement