13 #include "findwidget.h"
14 #include "mainwindow.h"
17 extern Main *mainWindow;
19 FindWidget::FindWidget(QWidget *)
21 QVBoxLayout* mainLayout = new QVBoxLayout;
22 QHBoxLayout *row2Layout = new QHBoxLayout;
24 QLabel *label=new QLabel;
25 label->setText (tr("Find:","FindWidget"));
27 // Create LineEdit (here QComboBox)
28 findcombo = new QComboBox;
29 findcombo->setMinimumWidth(250);
30 findcombo->setEditable(true);
32 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
33 findcombo->setSizePolicy(sizePolicy);
34 connect ( findcombo, SIGNAL( highlighted(int) ),
35 this, SLOT( nextPressed() ) );
36 connect ( findcombo, SIGNAL( editTextChanged(const QString &) ),
37 this, SLOT( findTextChanged(const QString&) ) );
39 nextbutton = new QPushButton;
40 nextbutton->setIcon (QPixmap(":/find.png"));
41 //nextbutton->setText (tr("Find","Find widget"));
42 connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
44 // QAction needed to only activate shortcut while FindWidget has focus
45 QAction *a=new QAction (nextbutton->text(),this);
46 a->setShortcut (Qt::Key_Return);
47 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
48 connect ( a, SIGNAL( triggered() ), this, SLOT( nextPressed() ) );
51 row2Layout->addWidget (label);
52 row2Layout->addWidget(findcombo);
53 row2Layout->addWidget(nextbutton);
55 mainLayout->addLayout (row2Layout);
57 setLayout (mainLayout);
61 QString FindWidget::getFindText()
63 return findcombo->currentText();
66 void FindWidget::cancelPressed()
69 emit (hideFindWidget() );//Restore focus
72 void FindWidget::nextPressed()
74 emit (nextButton(findcombo->currentText() ) );
77 void FindWidget::findTextChanged(const QString&)
79 setStatus (Undefined);
82 void FindWidget::setFocus()
84 findcombo->lineEdit()->selectAll();
85 findcombo->lineEdit()->setFocus();
88 void FindWidget::setStatus (Status st)
90 if (st==status) return;
97 case Success: c=QColor (120,255,120); break;
98 case Failed: c=QColor (255,120,120); break;
99 default: c=QColor (255,255,255);
101 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
102 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
103 findcombo->setPalette(p);