findwidget.cpp
author insilmaril
Thu, 26 Nov 2009 14:55:23 +0000
changeset 810 a9295db4dcbf
parent 808 b163492fda17
child 811 c79486b7cb4b
permissions -rw-r--r--
More fixes to new findwidget
     1 #include <QLineEdit>
     2 #include <QVBoxLayout>
     3 #include <QLabel>
     4 
     5 #include "findwidget.h"
     6 
     7 
     8 extern QString vymName;
     9 
    10 FindWidget::FindWidget(QWidget *)
    11 {
    12     QVBoxLayout* mainLayout = new QVBoxLayout;
    13     QHBoxLayout *row2Layout = new QHBoxLayout;
    14     
    15 	// Create Buttons
    16 	cancelbutton = new QPushButton;
    17 	cancelbutton->setText(tr("Cancel"));
    18 	cancelbutton->setShortcut (Qt::Key_Escape);
    19 	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
    20 	
    21 	QLabel *label=new QLabel;
    22 	label->setText (tr("Find:","FindWidget"));
    23 	
    24 	// Create LineEdit (here QComboBox)
    25     findcombo = new QComboBox;
    26 	findcombo->setMinimumWidth(250);
    27 	findcombo->setEditable(true);
    28 	connect ( findcombo, SIGNAL( highlighted(int) ), 
    29 		this, SLOT( nextPressed() ) );
    30 	connect ( findcombo, SIGNAL( textChanged(const QString &) ), 
    31 		this, SLOT( findTextChanged(const QString&) ) );
    32 
    33 	nextbutton = new QPushButton;
    34 	nextbutton->setText (tr("Next","Find widget"));
    35 	nextbutton->setDefault (true);
    36 	nextbutton->setShortcut (Qt::Key_Return);
    37 	//nextbutton->setShortcutContext (Qt::WidgetShortcut);
    38 	connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
    39 
    40 	row2Layout->addWidget (cancelbutton);
    41 	row2Layout->addWidget (label);
    42 	row2Layout->addWidget(findcombo);
    43 	row2Layout->addWidget(nextbutton);
    44 
    45 	mainLayout->addLayout (row2Layout);
    46 
    47 	setLayout (mainLayout);
    48 	setStatus (Undefined);
    49 }
    50 
    51 void FindWidget::popup()
    52 {
    53 	show();
    54 	findcombo->lineEdit()->selectAll();
    55 	findcombo->setFocus();
    56 }
    57 
    58 void FindWidget::cancelPressed()
    59 {
    60 	hide();
    61 }
    62 
    63 void FindWidget::nextPressed()
    64 {
    65 	emit (nextButton(findcombo->currentText() ) );
    66 }
    67 
    68 void FindWidget::findTextChanged(const QString&)
    69 {
    70 	emit (somethingChanged() );
    71 }
    72 
    73 void FindWidget::setStatus (Status st)
    74 {
    75 	QPalette p=palette();
    76 	QColor c;
    77 	switch (st)
    78 	{
    79 		case Success: c=QColor (100,255,100); break;
    80 		case Failed:  c=QColor (255,100,100); break;
    81 		default:  c=QColor (255,255,255); 
    82 	}
    83     p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
    84     p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
    85     findcombo->setPalette(p);
    86 }
    87