C ++ exercises (III)

Source: Internet
Author: User
// Finddialog. h
# Ifndef finddialog_h
# Define finddialog_h
# Include <qdialog>
Class qcheckbox;
Class qlabel;
Class qlineedit;
Class qpushbutton;

Class finddialog: Public qdialog
{
Q_object
Public:
Finddialog (qwidget * parent = 0 );
Signals: // declare the signal
Void findnext (const qstring & STR, QT: casesensiti1_cs );
Void findprev (const qstring & STR, QT: casesensiti1_cs );
Private slots: // declaration slot
Void findclicked ();
Void enablefindbutton (const qstring & Str );
PRIVATE:
Qlabel * lable;
Qlineedit * lineedit;
Qcheckbox * casecheckbox;
Qcheckbox * backwardcheckbox;
Qpushbutton * findbtn;
Qpushbutton * closebtn;
};

# Endif

// Finddialog. cpp
# Include <qtgui>
# Include "finddialog. H"

Finddialog: finddialog (qwidget * parent): qdialog (parent)
{

This-> lable = new qlabel (TR ("find & what:"), this );
This-> lineedit = new qlineedit (this );
Lable-> setbuddy (lineedit );

Casecheckbox = new qcheckbox (TR ("Match & Case"), this );
Backwardcheckbox = new qcheckbox (TR ("Search & backward"), this );

Findbtn = new qpushbutton (TR ("& find"), this );
Findbtn-> setdefault (true );
Findbtn-> setenabled (false );
Closebtn = new qpushbutton (TR ("close"), this );

Qobject: connect (lineedit, signal (textchanged (const qstring &), this, slot (enablefindbutton (const qstring &)));
Qobject: connect (findbtn, signal (clicked (), this, slot (findclicked ()));
Qobject: connect (closebtn, signal (clicked (), this, slot (close ()));

Qhboxlayout * topleftlayout = new qhboxlayout;
Topleftlayout-> addwidget (lable );
Topleftlayout-> addwidget (lineedit );

Qvboxlayout * leftlayout = new qvboxlayout;
Leftlayout-> addlayout (topleftlayout );
Leftlayout-> addwidget (casecheckbox );
Leftlayout-> addwidget (backwardcheckbox );

Qvboxlayout * rightlayout = new qvboxlayout;
Rightlayout-> addwidget (findbtn );
Rightlayout-> addwidget (closebtn );
Rightlayout-> addstretch (1 );

Qhboxlayout * mainlayout = new qhboxlayout (this );
Mainlayout-> setmargin (11 );
Mainlayout-> setspacing (5 );
Mainlayout-> addlayout (leftlayout );
Mainlayout-> addlayout (rightlayout );
This-> setwindowtitle (TR ("find "));
This-> setfixedheight (sizehint (). Height ());
}

Void finddialog: findclicked ()
{
Qstring text = lineedit-> text ();
Qt: casesensiti1_cs = casecheckbox-> ischecked ()? Qt: casesensitive: QT: caseinsensitive;

If (backwardcheckbox-> ischecked ())
Emit findprev (text, CS); // transmits "Forward search signal"
Else
Emit findnext (text, CS); // transmits "Backward Search signal"
}

Void finddialog: enablefindbutton (const qstring & Str)
{
Findbtn-> setenabled (! Str. isempty ());
}

// Main. cpp
# Include <qapplication>
# Include "finddialog. H"

Int main (INT argc, char * argv [])
{
Qapplication app (argc, argv );
Finddialog * dialog = new finddialog;
Dialog-> show ();
Return app.exe C ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.