11 #include "findwidget.h"
14 extern QString iconPath;
16 FindWidget::FindWidget(QWidget *)
18 QVBoxLayout* mainLayout = new QVBoxLayout;
19 QHBoxLayout *row2Layout = new QHBoxLayout;
22 cancelbutton = new QPushButton;
23 //cancelbutton->setText(tr("Cancel"));
24 cancelbutton->setIcon (QIcon (iconPath+"fileclose.png"));
25 cancelbutton->setShortcut (Qt::Key_Escape);
26 connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
28 QLabel *label=new QLabel;
29 label->setText (tr("Find:","FindWidget"));
31 // Create LineEdit (here QComboBox)
32 findcombo = new QComboBox;
33 findcombo->setMinimumWidth(250);
34 findcombo->setEditable(true);
36 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
37 findcombo->setSizePolicy(sizePolicy);
38 connect ( findcombo, SIGNAL( highlighted(int) ),
39 this, SLOT( nextPressed() ) );
40 connect ( findcombo, SIGNAL( textChanged(const QString &) ),
41 this, SLOT( findTextChanged(const QString&) ) );
43 nextbutton = new QPushButton;
44 nextbutton->setText (tr("Next","Find widget"));
45 nextbutton->setDefault (true);
46 nextbutton->setShortcut (Qt::Key_Return);
47 //nextbutton->setShortcutContext (Qt::WidgetShortcut);
48 connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
50 row2Layout->addWidget (cancelbutton);
51 row2Layout->addWidget (label);
52 row2Layout->addWidget(findcombo);
53 row2Layout->addWidget(nextbutton);
55 mainLayout->addLayout (row2Layout);
57 setLayout (mainLayout);
61 void FindWidget::popup()
64 findcombo->lineEdit()->selectAll();
65 findcombo->setFocus();
66 setStatus (Undefined);
69 void FindWidget::cancelPressed()
72 emit (hideFindWidget() );
75 void FindWidget::nextPressed()
77 emit (nextButton(findcombo->currentText() ) );
80 void FindWidget::findTextChanged(const QString&)
82 setStatus (Undefined);
85 void FindWidget::setStatus (Status st)
87 if (st==status) return;
94 case Success: c=QColor (120,255,120); break;
95 case Failed: c=QColor (255,120,120); break;
96 default: c=QColor (255,255,255);
98 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
99 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
100 findcombo->setPalette(p);