findwindow.cpp
author insilmaril
Tue, 05 Sep 2006 11:53:54 +0000
changeset 371 ebefeea77f2f
parent 370 97f5d07bf47d
child 375 06ab6df252fa
permissions -rw-r--r--
fixed default shortcut in findwindow
     1 #include <QLineEdit>
     2 #include <QVBoxLayout>
     3 #include <QLabel>
     4 
     5 #include "findwindow.h"
     6 #include "version.h"
     7 
     8 
     9 FindWindow::FindWindow(QWidget* parent)
    10 	: QGroupBox( tr("Find"), parent )
    11 
    12 {
    13 	setWindowTitle(__VYM " - " +tr("Find Text"));
    14 	//resize (180,130);
    15 	//move (130,130);
    16 
    17     QVBoxLayout* mainLayout = new QVBoxLayout;
    18     
    19     QHBoxLayout *row1Layout = new QHBoxLayout;
    20     // Create a Label
    21     QLabel* label = new QLabel;
    22     label->setText( tr("Text to find:"));
    23     row1Layout->addWidget( label );
    24 
    25 
    26 	// Create LineEdit (here QComboBox)
    27     QHBoxLayout *row2Layout = new QHBoxLayout;
    28     findcombo = new QComboBox;
    29 	findcombo->setMinimumWidth(150);
    30 	findcombo->setEditable(true);
    31 	connect ( findcombo, SIGNAL( highlighted(int) ), 
    32 		this, SLOT( findPressed() ) );
    33 	connect ( findcombo, SIGNAL( textChanged(const QString &) ), 
    34 		this, SLOT( findTextChanged(const QString&) ) );
    35     //findcombo->insertItem( "Normal", -1 );
    36 
    37 	row2Layout->addWidget(findcombo);
    38 
    39 	// Create Buttons
    40     QHBoxLayout *row3Layout = new QHBoxLayout;
    41 	clearbutton = new QPushButton;
    42 	clearbutton->setText(tr("Clear"));
    43 	connect ( clearbutton, SIGNAL( clicked() ), this, SLOT( clearLineEdit() ) );
    44 	row3Layout->addWidget (clearbutton);
    45 	
    46 	/*
    47 	QSpacerItem *si1= new QSpacerItem (10,0,QSizePolicy::Minimum, QSizePolicy::Expanding );
    48 	row3Layout->addItem(si1);
    49 	*/
    50 	
    51 	cancelbutton = new QPushButton;
    52 	cancelbutton->setText(tr("Cancel"));
    53 	cancelbutton->setShortcut (Qt::Key_Escape);
    54 	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
    55 	row3Layout->addWidget (cancelbutton);
    56 
    57 /*
    58 	QSpacerItem *si2= new QSpacerItem (10,0,QSizePolicy::Fixed, QSizePolicy::Fixed);
    59 	row3Layout->addItem(si2);
    60 	*/
    61 	
    62 	findbutton = new QPushButton;
    63 	findbutton->setText (tr("Find"));
    64 	findbutton->setDefault (true);
    65 	findbutton->setShortcut (Qt::Key_Return);
    66 	connect ( findbutton, SIGNAL( clicked() ), this, SLOT( findPressed() ) );
    67 
    68 	row3Layout->addWidget(findbutton);
    69 
    70 	mainLayout->addLayout (row1Layout);
    71 	mainLayout->addLayout (row2Layout);
    72 	mainLayout->addLayout (row3Layout);
    73 	setLayout (mainLayout);
    74 }
    75 
    76 void FindWindow::popup()
    77 {
    78 	show();
    79 	findcombo->lineEdit()->selectAll();
    80 	findcombo->setFocus();
    81 }
    82 
    83 void FindWindow::cancelPressed()
    84 {
    85 	hide();
    86 }
    87 
    88 void FindWindow::findPressed()
    89 {
    90 	emit (findButton(findcombo->currentText() ) );
    91 }
    92 
    93 void FindWindow::findTextChanged(const QString&)
    94 {
    95 	emit (somethingChanged() );
    96 }
    97 
    98 void FindWindow::clearLineEdit()
    99 {
   100 	findcombo->lineEdit()->clear();
   101 }