Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 74 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
74
Dung lượng
326,28 KB
Nội dung
501 Chapter 19 ✦ The Widgets of KDE File #include <kbuttonbox.h> Base Classes QObject QPaintDevice QWidget Qt Constructors KButtonBox(QWidget *parent, int _orientation = HORIZONTAL, int border = 0, int _autoborder = 6); Methods QPushButton *addButton(const QString &text, bool noexpand = FALSE); void addStretch(int scale = 1); void layout(); virtual void resizeEvent(QResizeEvent *); virtual QSize sizeHint() const; Enums enum (anon) { VERTICAL=1, HORIZONTAL=2 }; You can find examples of KButtonBox in Chapter 7. KCharSelect The KCharSelect widget enables the user to select a font, and then select a single character from the font. File #include <kcharselect.h> Base Classes QFrame QHBox QObject QPaintDevice QVBox QWidget Qt Constructors KCharSelect(QWidget *parent, const char *name, const QString &font = QString::null, const QChar &chr = , int tableNum = 0); Methods virtual QChar chr(); virtual void enableFontCombo(bool e); virtual void enableTableSpinBox(bool e); virtual QString font(); virtual bool isFontComboEnabled(); virtual bool isTableSpinBoxEnabled(); virtual void setChar(const QChar &chr); Cross- Reference 4682-1 ch19.f.qc 11/20/00 15:44 Page 501 502 Part III ✦ Reference and Mechanics virtual void setFont(const QString &font); virtual void setTableNum(int tableNum); virtual QSize sizeHint() const; virtual int tableNum(); Signals void activated(const QChar &c); void activated(); void focusItemChanged(); void focusItemChanged(const QChar &c); void fontChanged(const QString &_font); void highlighted(const QChar &c); void highlighted(); The following example displays the KCharSelect window shown in Figure 19-4: /* showcharselect.cpp */ #include <kapp.h> #include <kcharselect.h> #include <qstring.h> int main(int argc,char **argv) { KApplication app(argc,argv,”showcharselect”); QWidget *widget = new QWidget(); KCharSelect *kcharselect = new KCharSelect(widget,”charselect”); kcharselect->resize(kcharselect->sizeHint()); widget->resize(kcharselect->sizeHint()); widget->show(); app.setMainWidget(widget); return(app.exec()); } Figure 19-4: A KCharSelect widget with both a font and character selected 4682-1 ch19.f.qc 11/20/00 15:44 Page 502 503 Chapter 19 ✦ The Widgets of KDE KCharSelectTable The KCharSelectTable widget is the character-display portion of the KCharSelect widget. File #include <kcharselect.h> Base Classes QFrame QObject QPaintDevice QTableView QWidget Qt Constructors KCharSelectTable(QWidget *parent, const char *name, const QString &_font, const QChar &_chr, int _tableNum); Methods virtual QChar chr(); virtual void setChar(const QChar &_chr); virtual void setFont(const QString &_font); virtual void setTableNum(int _tableNum); virtual QSize sizeHint() const; Signals void activated(const QChar &c); void activated(); void focusItemChanged(); void focusItemChanged(const QChar &c); void highlighted(const QChar &c); void highlighted(); void tableDown(); void tableUp(); For an example, see KCharSelect. KCModule The KCModule widget is the base class of all of the control modules. The resulting widget appears as one of the kcontrol windows, and can be used to adjust configuration settings. File #include <kcmodule.h> Base Classes QObject QPaintDevice QWidget Qt 4682-1 ch19.f.qc 11/20/00 15:44 Page 503 504 Part III ✦ Reference and Mechanics Constructors KCModule(QWidget *parent = 0, const char *name = 0) : QWidget ( parent , name ) , _btn ( Help | Default | Reset | Cancel | Apply | Ok ); Methods int buttons(); virtual void defaults(); static void init(); virtual void load(); virtual QString quickHelp(); virtual void save(); virtual void sysdefaults(); Signals void changed(bool state); Enums enum Button { Help=1, Default=2, Reset=4, Cancel=8, Apply=16, Ok=32, SysDefault=64 }; KColorButton The KColorButton widget is a pushbutton filled with a color instead of text; when selected, it pops up a dialog that enables the user to select another color. File #include <kcolorbtn.h> Base Classes QButton QObject QPaintDevice QPushButton QWidget Qt Constructors KColorButton(QWidget *parent, const char *name = 0L); KColorButton(const QColor &c, QWidget *parent, const char *name = 0L); Methods const QColor color() const; void setColor(const QColor &c); Signals void changed(const QColor &newColor); The following example creates a KColorButton using red. As shown in Figure 19-5, selecting the button causes the dialog to appear. The user can then select another color, which will both change the color of the KColorButton and emit the changed() signal. 4682-1 ch19.f.qc 11/20/00 15:44 Page 504 505 Chapter 19 ✦ The Widgets of KDE /* showcolorbutton.cpp */ #include <kapp.h> #include <kcolorbtn.h> #include <qcolor.h> int main(int argc,char **argv) { KApplication app(argc,argv,”showcolorbutton”); KColorButton *colorbutton = new KColorButton(0,”colorbutton”); colorbutton->setColor(QColor(“red”)); colorbutton->resize(colorbutton->sizeHint()); colorbutton->show(); app.setMainWidget(colorbutton); return(app.exec()); } Figure 19-5: The KColorButton pops up a dialog for color selection. KColorCells The KColorCells widget displays a collection of colors and enables the user to select one of them.File #include <kcolordlg.h> Base Classes QFrame QObject QPaintDevice QTableView QWidget Qt 4682-1 ch19.f.qc 11/20/00 15:44 Page 505 506 Part III ✦ Reference and Mechanics Constructors KColorCells(QWidget *parent, int rows, int cols); Methods QColor color(int indx); int getSelected(); int numCells(); void setAcceptDrags(bool _acceptDrags); void setColor(int colNum, const QColor &col); void setShading(bool _shade); Signals void colorSelected(int col); The following example displays the list of color cells shown in Figure 19-6: /* showcolorcells.cpp */ #include <kapp.h> #include <kcolordlg.h> int main(int argc,char **argv) { KApplication app(argc,argv,”showcolorcells”); KColorCells *colorcells = new KColorCells(0,1,5); colorcells->setColor(0,QColor(“magenta”)); colorcells->setColor(1,QColor(“red”)); colorcells->setColor(2,QColor(“blue”)); colorcells->setColor(3,QColor(“green”)); colorcells->setColor(4,QColor(“cyan”)); colorcells->show(); app.setMainWidget(colorcells); return(app.exec()); } Figure 19-6: A KColorCells widget displaying a row of five colors KColorCombo The KColorCombo widget displays a pull-down list of colors for selection with the mouse. 4682-1 ch19.f.qc 11/20/00 15:44 Page 506 507 Chapter 19 ✦ The Widgets of KDE File #include <kcolordlg.h> Base Classes QComboBox QObject QPaintDevice QWidget Qt Constructors KColorCombo(QWidget *parent, const char *name = 0L); Methods void setColor(const QColor &col); Slots void slotActivated(int index); void slotHighlighted(int index); Signals void activated(const QColor &col); void highlighted(const QColor &col); The following example displays a KColorCombo widget. Figure 19-7 shows the KColorCombo widget after it has been pulled down and a color selection made. /* showcolorcombo.cpp */ #include <kapp.h> #include <kcolordlg.h> int main(int argc,char **argv) { KApplication app(argc,argv,”showcolorcombo”); KColorCombo *colorcombo = new KColorCombo(0,”colorcombo”); colorcombo->show(); app.setMainWidget(colorcombo); return(app.exec()); } Figure 19-7: A KColorCombo widget enables color selection from a list. 4682-1 ch19.f.qc 11/20/00 15:44 Page 507 508 Part III ✦ Reference and Mechanics KColorDialog The KColorDialog is a color selection dialog with several features, including custom colors. File #include <kcolordlg.h> Base Classes KDialog KDialogBase QDialog QObject QPaintDevice QWidget Qt Constructors KColorDialog(QWidget *parent = 0L, const char *name = 0L, bool modal = FALSE); Methods QColor color(); static int getColor(QColor &theColor, QWidget *parent = 0L); static QColor grabColor(const QPoint &p); Slots void setColor(const QColor &col); Signals void colorSelected(const QColor &col); You can find an example of the KColorDialog widget in Chapter 11. KColorPatch The KColorPatch widget displays a rectangular region of color and responds to being selected with the mouse. File #include <kcolordlg.h> Base Classes QFrame QObject QPaintDevice QWidget Qt Constructors KColorPatch(QWidget *parent); Methods void setColor(const QColor &col); Cross- Reference 4682-1 ch19.f.qc 11/20/00 15:44 Page 508 509 Chapter 19 ✦ The Widgets of KDE Signals void colorChanged(const QColor &); The following example uses a KColorPatch widget as the top-level window to display a region of color, as shown in Figure 19-8. /* showcolorpatch.cpp */ #include <kapp.h> #include <kcolordlg.h> int main(int argc,char **argv) { KApplication app(argc,argv,”showcolorpatch”); KColorPatch *colorpatch = new KColorPatch(0); colorpatch->setColor(QColor(“blue”)); colorpatch->show(); app.setMainWidget(colorpatch); return(app.exec()); } Figure 19-8: A KColorPatch displaying a region of color KComboBox The KComboBox widget is a button that allows the user to make a selection from a list. It always displays the current selection at its top. File #include <kcombobox.h> Base Classes KCompletionBase QComboBox QObject QPaintDevice QWidget Qt Inherited By KFileComboBox KFileFilter KURLComboBox Constructors KComboBox(QWidget *parent = 0, const char *name = 0); KComboBox(bool rw, QWidget *parent = 0, const char *name = 0); Methods bool autoCompletion() const; int cursorPosition() const; 4682-1 ch19.f.qc 11/20/00 15:44 Page 509 510 Part III ✦ Reference and Mechanics bool isContextMenuEnabled() const; bool isEditable() const; virtual void setAutoCompletion(bool autocomplete); virtual void setEnableContextMenu(bool showMenu); Slots void rotateText(KeyBindingType); Signals void completion(const QString &); void nextMatch(KeyBindingType); void previousMatch(KeyBindingType); void returnPressed(); void returnPressed(const QString &); void rotateDown(KeyBindingType); void rotateUp(KeyBindingType); The following example creates a KComboBox with four selections. Figure 19-9 shows the widget after the mouse has been used to pop up the list, and with the third selection as the default. /* showcombobox.cpp */ #include <kapp.h> #include <kcombobox.h> const char *list[] = { “First Selection”, “Second Selection”, “Third Selection”, “Fourth Selection” }; int main(int argc,char **argv) { KApplication app(argc,argv,”showcombobox”); KComboBox *combobox = new KComboBox(); combobox->insertStrList(list,4); combobox->show(); app.setMainWidget(combobox); return(app.exec()); } Figure 19-9: A KComboBox with the third list member selected 4682-1 ch19.f.qc 11/20/00 15:44 Page 510 [...]... margin, 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 515 Chapter 19 ✦ The Widgets of KDE int spacing); static int spacingHint(); Slots virtual void setCaption(const QString &caption); virtual void setPlainCaption(const QString &caption); Signals void layoutHintChanged(); KDialogBase The KDialogBase is the base class for building dialogs in KDE Among other things, it contains the standard set of KDE buttons... user2Clicked(); user3Clicked(); yesClicked(); Enums enum ButtonCode { Help=0x00000001, Default=0x00000002, Ok=0x00000004, Apply=0x000000 08, Try=0x00000010, Cancel=0x00000020, Close=0x00000040, User1=0x00000 080 , User2=0x00000100, User3=0x00000200, No=0x00000 080 , Yes=0x00000100, Stretch=0x80000000 }; enum ActionButtonStyle { ActionStyle0=0, ActionStyle1, ActionStyle2, ActionStyle3, ActionStyle4, ActionStyleMAX };... headerCloseButtonClicked(); headerDockbackButtonClicked(); iMBeingClosed(); setDockDefaultPos(); Enums enum DockPosition { DockNone=0, DockTop=0x0001, DockLeft=0x0002, DockRight=0x0004, DockBottom=0x00 08, DockCenter=0x0010, DockDesktop=0x0020, DockCorner=DockTop|DockLeft|DockRight|DockBottom, DockFullSite=DockCorner|DockCenter, DockFullDocking=DockFullSite|DockDesktop }; The following example uses three KDockWidget widgets... the KEdGotoLine dialog shown in Figure 19- 18: /* showedgotoline.cpp */ #include #include int main(int argc,char **argv) { KApplication app(argc,argv,”showedgotoline”); KEdGotoLine *edgotoline = new KEdGotoLine(); edgotoline->show(); return(app.exec()); } 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 527 Chapter 19 ✦ The Widgets of KDE Figure 19- 18: The KEdGotoLine dialog prompts for a line... }; enum DialogType { TreeList=KJanusWidget::TreeList, Tabbed=KJanusWidget::Tabbed, Plain=KJanusWidget::Plain, Swallow=KJanusWidget::Swallow, IconList=KJanusWidget::IconList }; 517 4 682 -1 ch19.f.qc 5 18 11/20/00 15:44 Page 5 18 Part III ✦ Reference and Mechanics There are several examples of using KDialogBase to build dialogs in Chapter 4 CrossReference KDialogBaseButton The KDialogBaseButton is used internally... misspelling(QString word, QStringList *, unsigned pos); void repaintAll(); void replace_all_slot(); void replace_search_slot(); void replace_slot(); void replacedone_slot(); 527 4 682 -1 ch19.f.qc 5 28 11/20/00 15:44 Page 5 28 Part III ✦ Reference and Mechanics void search_slot(); void searchdone_slot(); Signals void CursorPositionChanged(); void gotUrlDrop(QDropEvent *e); void toggle_overwrite_signal();... **argv) { KApplication app(argc,argv,”showdatepicker”); KDatePicker *datepicker = new KDatePicker(); datepicker->resize(datepicker->sizeHint()); datepicker->show(); 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 513 Chapter 19 ✦ The Widgets of KDE app.setMainWidget(datepicker); return(app.exec()); } Figure 19-10: A KDatePicker widget KDateTable A KDateTable displays a single month and enables the user to select... #include 513 4 682 -1 ch19.f.qc 514 11/20/00 15:44 Page 514 Part III ✦ Reference and Mechanics int main(int argc,char **argv) { KApplication app(argc,argv,”showdatetable”); KDateTable *datetable = new KDateTable(); datetable->show(); app.setMainWidget(datetable); return(app.exec()); } Figure 19-11: A KDateTable widget KDialog The KDialog widget is a base class for modeless KDE widgets It extends... = 0, const char *name = 0); KDirectionButton(ArrowType d, QWidget *parent = 0, const char *name = 0); Methods ArrowType direction(); void setDirection(ArrowType d); 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 519 Chapter 19 ✦ The Widgets of KDE The following example displays the right pointing arrow shown in Figure 19-12 The arrow direction names are UpArrow, DownArrow, LeftArrow, and RightArrow /* showdirectionbutton.cpp... any widget that you would like to be one of the dockable widgets in a KDockMainWindow widget File #include Base Classes QObject QPaintDevice QWidget Qt 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 521 Chapter 19 ✦ The Widgets of KDE Constructors KDockWidget(KDockManager *dockManager, const char *name, const QPixmap &pixmap, QWidget *parent = 0L); Methods KDockManager *dockManager(); int dockSite(); . Default=0x00000002, Ok=0x00000004, Apply=0x000000 08, Try=0x00000010, Cancel=0x00000020, Close=0x00000040, User1=0x00000 080 , User2=0x00000100, User3=0x00000200, No=0x00000 080 , Yes=0x00000100, Stretch=0x80000000 }; enum ActionButtonStyle. *parent); Methods void setColor(const QColor &col); Cross- Reference 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 5 08 509 Chapter 19 ✦ The Widgets of KDE Signals void colorChanged(const QColor &); The following. setDirection(ArrowType d); Cross- Reference Cross- Reference 4 682 -1 ch19.f.qc 11/20/00 15:44 Page 5 18 519 Chapter 19 ✦ The Widgets of KDE The following example displays the right pointing arrow