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