findwindow.cpp
author insilmaril
Wed, 25 Nov 2009 10:58:21 +0000
changeset 807 f9f7922989d8
parent 403 7c3ee77f4449
permissions -rw-r--r--
Added demos/vym-contribute.vym, fixes for selecting items
     1 #include <QLineEdit>
     2 #include <QVBoxLayout>
     3 #include <QLabel>
     4 
     5 #include "findwindow.h"
     6 
     7 
     8 extern QString vymName;
     9 
    10 FindWindow::FindWindow(QWidget* parent)
    11 	//: QGroupBox( tr("Find"), parent )
    12 
    13 {
    14 	//setWindowTitle(vymName + " - " +tr("Find Text"));
    15 
    16     QVBoxLayout* mainLayout = new QVBoxLayout;
    17     
    18     QHBoxLayout *row1Layout = new QHBoxLayout;
    19 	/*
    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(250);
    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 
    36 	row2Layout->addWidget(findcombo);
    37 
    38 	// Create Buttons
    39     //QHBoxLayout *row3Layout = new QHBoxLayout;
    40 	clearbutton = new QPushButton;
    41 	clearbutton->setText(tr("Clear"));
    42 	connect ( clearbutton, SIGNAL( clicked() ), this, SLOT( clearLineEdit() ) );
    43 	row2Layout->addWidget (clearbutton);
    44 	
    45 	cancelbutton = new QPushButton;
    46 	cancelbutton->setText(tr("Cancel"));
    47 	cancelbutton->setShortcut (Qt::Key_Escape);
    48 	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
    49 	row2Layout->addWidget (cancelbutton);
    50 	
    51 	findbutton = new QPushButton;
    52 	findbutton->setText (tr("Find"));
    53 	findbutton->setDefault (true);
    54 	findbutton->setShortcut (Qt::Key_Return);
    55 	connect ( findbutton, SIGNAL( clicked() ), this, SLOT( findPressed() ) );
    56 
    57 	//row2Layout->addStretch(2);
    58 	row2Layout->addWidget(findbutton);
    59 
    60 	mainLayout->addLayout (row1Layout);
    61 	mainLayout->addLayout (row2Layout);
    62 	//mainLayout->addLayout (row3Layout);
    63 	setLayout (mainLayout);
    64 }
    65 
    66 void FindWindow::popup()
    67 {
    68 	show();
    69 	findcombo->lineEdit()->selectAll();
    70 	findcombo->setFocus();
    71 }
    72 
    73 void FindWindow::cancelPressed()
    74 {
    75 	hide();
    76 }
    77 
    78 void FindWindow::findPressed()
    79 {
    80 	emit (findButton(findcombo->currentText() ) );
    81 }
    82 
    83 void FindWindow::findTextChanged(const QString&)
    84 {
    85 	emit (somethingChanged() );
    86 }
    87 
    88 void FindWindow::clearLineEdit()
    89 {
    90 	findcombo->lineEdit()->clear();
    91 }