📄 ktoolbar.h
字号:
/** * Returns true if button is on, false if button is off. * If button is not a toggle button returns false * @see #setToggle */ bool isButtonOn (int id); /** * Sets text in Lined. * Cursor is set at end of text. */ void setLinedText (int id, const char *text); /** * Returns Lined text. * If you want to store this text, you have to deep-copy it somwhere. */ const char *getLinedText (int id); /** * Inserts text in combo id with at position index. */ void insertComboItem (int id, const char *text, int index); /** * Inserts list in combo id at position index */ void insertComboList (int id, QStrList *list, int index); /** * Removes item index from Combo id. */ void removeComboItem (int id, int index); /** * Sets item index to be current item in Combo id. */ void setCurrentComboItem (int id, int index); /** * Changes item index in Combo id to text. * index = -1 means current item (one displayed in the button). */ void changeComboItem (int id, const char *text, int index=-1); /** * Clears combo id. * Does not delete it or hide it. */ void clearCombo (int id); /** * Returns text of item index from Combo id. * index = -1 means current item */ const char *getComboItem (int id, int index=-1); /** * This returns pointer to Combo. Example: * <pre> * KCombo *combo = toolbar->getCombo(combo_id); * </pre> * That way you can get access to other public methods * that @ref KCombo provides. @ref KCombo is KDE enhancement * of @ref QComboBox . KCombo inherits QComboBox, so you can * use pointer to QComboBox too. */ KCombo * getCombo(int id); /** * This returns pointer to KToolBarLined. Example: * <pre> * KLined * lined = toolbar->getKTollBarLined(lined_id); * </pre> * That way you can get access to other public methods * that @ref KLined provides. @ref KLined is the same thing * as @ref QLineEdit plus completion signals. */ KLined * getLined (int id); /** * This returns a pointer to KToolBarButton. Example: * <pre> * KToolBarButton * button = toolbar->getButton(button_id); * </pre> * That way you can get access to other public methods * that @ref KToolBarButton provides. Using of this method is not * recomended. */ KToolBarButton * getButton (int id); /** * Alignes item right. * This works only if toolbar is set to full width. * @see #setFullWidth */ void alignItemRight (int id, bool right = true); /** * This function is deprecated and might be removed. Use @ref #insertWidget * and @ref #getWidget instead.<br> * Returns pointer to inserted frame. Wrong ids are not tested. * Example: * <pre> * QFrame *frame = toolbar->getframe (frameid); * </pre> * You can do with this frame whatever you want, * except change its height (hardcoded). If you change its width * you will probbably have to call toolbar->@ref #updateRects (true) * @see QFrame * @see #updateRects */ QFrame * getFrame (int id); /** * Returns pointer to inserted widget. Wrong ids are not tested. * You can do with this whatever you want, * except change its height (hardcoded). If you change its width * you will probbably have to call toolbar->@ref #updateRects (true) * @see QWidget * @see #updateRects */ QWidget *getWidget (int id); /** * Sets item autosized. This works only if toolbar is set to full width. * ONLY ONE item can be autosized, and it has to be * the last left-aligned item. Items that come after this must be right * aligned. Items that can be right aligned are Lineds, Frames, Widgets and * Combos. Auto sized item will resize itself whenever toolbar geometry * changes, to last right-aligned item (or till end of toolbar if there * are no right aligned items * @see #setFullWidth * @see #alignItemRight */ void setItemAutoSized (int id, bool yes = true); /** * Removes item id. * Item is deleted. Toolbar is redrawn after it. */ void removeItem (int id); /** * Hides item. */ void hideItem (int id); /** * shows item. */ void showItem (int id); /** * Sets toolbar to full parent width (or to value set by setMaxWidth). * You have to call this function if you want to have right aligned items or * autosized item. <BR> * The toolbar is set to full width by default. * @see #alignItemRight * @see #setItemAutoSized */ void setFullWidth(bool flag = true); // Top and Bottom pos only /** * Enables or disables moving of toolbar. */ void enableMoving(bool flag = true); /** * Sets position of toolbar. This cannot be used to set toolbar flat. For * That, use @ref setFlat . * @see #BarPosition */ void setBarPos (BarPosition bpos); /** * Returns position of toolbar */ BarPosition barPos() {return position;}; /** * This shows, hides, or toggles toolbar. If toolbar floats, * hiding means minimizing. Warning: kwm will not show minimized toolbar * on taskbar. Therefore hiding means hiding. * @see #BarStatus */ bool enable(BarStatus stat); /** * Sets maximal height of vertical (Right or Left) toolbar. You normaly * do not have to call it, since it's called from * @ref KTopLevelWidget#updateRects * If you reimplement @ref KTopLevelWidget#resizeEvent or * KTopLevelWidget#updateRects, * be sure to call this function with maximal height toolbar can have. * In 0xFE cases out of 0xFF you don't need to use this function. * @see #updateRects */ void setMaxHeight (int h); // Set max height for vertical toolbars /** * Sets maximal width of horizontal (top or bottom) toolbar. This works * only for horizontal toolbars (at Top or Bottom), and has no effect * otherwise. Has no effect when toolbar is floating. */ void setMaxWidth (int dw); /** * Sets title for toolbar when it floats. Titles are however not (yet) * visible. You can't change toolbar's title while it's floating. */ void setTitle (const char *_title) {title = _title;}; /** * Enables or disables floating. * Floating is enabled by default. * This only disables menu entry Floating in popup menu, so * toolbar can still be moved by @ref #setBarPos or by dragging. * This function is obsolete and do not use it. If you want to make * toolbar static use @ref enableMoving */ void enableFloating (bool arrrrrrgh); /** * Sets the kind of painting for buttons between : 0 (only icons), * 1 (icon and text, text is left from icons), 2 (only text), * and 3 (icons and text, text is under icons). */ void setIconText(int it); /** * Redraw toolbar and resize it if resize is true. * You normaly don't have to call it, since it's called from * @ref KTopLevelWidget#updateRects or from resizeEvent. You can call it * if you manualy change width of inserted frame, or if you wish to force * toolbar to recalculate itself. <BR> * You don't want to fiddle with this. * @ref KtopLevelWidget works closely with toolbar. If you want to * subclass KTopLevelWidget to change its resize policy, hear this: <BR> * <BR> * resizeEvent() in KTopLevelWidget just calls updateRects, which handles * children sizes. Call updateRects when you're done with your things. <BR> * <BR> * If you want to handle everything yourself:<BR> * <BR> * KToolBar manages itself by calling toolbar->@ref #updateRects (true). * It will autosize itself, but won't move itself. * You have to do the moving. <BR> * First setup & move anything that is above toolbars (menus...). Then * setup statusbars and other horizontal things on bottom. Then loop through * all HORIZONTAL toolbars, call their updateRects(true), _then_ take their * size, an move them (note that they size themselves according to parent * width()). After you have looped through HORIZONTAL toolbars, calculate * the maximum height that vertical toolbars may have (this is your free * area height). Then loop through vertical toolbars, * @ref #setMaxHeight (calculated_max_height) on them, * call their updateRects(true), and _then_ move them to their locations. * In 0xFE cases out of 0xFF you don't need to use this function. * @see KtopLevelWidget#updateRects */ void updateRects(bool resize = false); /** * Returns minimal width for top-level window, so that toolbar * has only one row. */ QSize sizeHint(); /** * This method switches flat/unflat mode. Carefull: might not work * If toolbar is floating. */ void setFlat (bool flag); signals: /** * Emits when button id is clicked. */ void clicked(int id); /** * Emits when button id is double clicked. Note: you will always * recive two @ref #clicked , @ref #pressed and @ref #released signals. * There is no way to avoid it - at least no easy way. * If you need to resolve this all you can do is set up timers * which waits for @ref QApplication::doubleClickInterval to expire. * if in that time you don't get this signal, you may belive that * button was only clicked. * And please note that butons with popup menus do not emit this signal, * but those with delayed popup do. */ void doubleClicked (int id); /** * Emits when button id is pressed. */ void pressed(int); /** * Emits when button id is released. */ void released(int); /** * Emits when toggle button changes state * Emits also if you change state * with @ref #setButton or @ref #toggleButton * If you make a button normal again, with * @ref #setToggle (false), this signal won't * be emited. */ void toggled(int); /** * This signal is emmited when item id gets highlighted/unhighlighted * (i.e when mouse enters/exits). Note that this signal is emited from * all buttons (normal, disabled and toggle) even when there is no visible * change in buttons (meaning, buttons do not raise when mouse enters). * Parameter isHighlighted is true when mouse enters and false when * mouse exits. */ void highlighted(int id, bool isHighlighted); /** * Emits when toolbar changes its position, or when * item is removed from toolbar. This is normaly connected to * @ref KTopLevelWidget::updateRects. * If you subclass @ref KTopLevelWidget and reimplement * @ref KTopLevelWidget::resizeEvent or * @ref KTopLevelWidget::updateRects, be sure to connect to * this signal. You can connect this signal to slot that * doesn't take parameter. * @see #updateRects */ void moved( BarPosition ); /** * Internal. This signal is emited when toolbar detects changing of * following parameters: * highlighting, button-size, button-mode. This signal is * internal, aimed to buttons. */ void modechange (); private: QList<KToolBarItem> items; const char *title; bool fullWidth; BarPosition position; bool moving; QWidget *Parent; int toolbarWidth; int toolbarHeight; int oldX; int oldY; int oldWFlags; int max_width; int max_height; BarPosition lastPosition; // Where was I last time I was? BarPosition movePos; // Where was I moved to? bool mouseEntered; // Did the mouse touch the cheese? bool horizontal; // Do I stand tall? bool localResize; // Am I trying to understand recursion? bool wasFullWidth; // Was I loong when I was? bool haveAutoSized; // Do I have a problem? KToolBoxManager *mgr; protected: QPopupMenu *context; void drawContents ( QPainter *); void resizeEvent(QResizeEvent*); void paintEvent(QPaintEvent*); void closeEvent (QCloseEvent *); void mousePressEvent ( QMouseEvent *); void init(); void layoutVertical (); void layoutHorizontal (); void leaveEvent (QEvent *e); private slots: void ButtonClicked(int); void ButtonDblClicked( int id ); void ButtonPressed(int); void ButtonReleased(int); void ButtonToggled(int); void ButtonHighlighted(int,bool); void ContextCallback(int); void slotReadConfig (); void slotHotSpot (int i); protected: void mouseMoveEvent(QMouseEvent*); void mouseReleaseEvent ( QMouseEvent *);private: QPoint pointerOffset; QPoint parentOffset; int item_size; // normal: 26 int icon_text; // 1 = icon+text, 0 icon+tooltip bool highlight; // yes/no QSize szh; // Size for sizeHint bool fixed_size; // do not change the toolbar size bool transparent; // type of moving };/************************************************************************* * KRadioGroup * *************************************************************************/ /** * KRadioGroup is class for group of radio butons in toolbar. * Take toggle buttons which you already inserted into toolbar, * create KRadioGroup instance and add them here. * All buttons will emit signals toggled (bool) (or you can * use sitgnal @ref #toggled (int id) from toolbar). When one button is set * down, all others are unset. All buttons emit signals - those who * "go down" and those who "go up". * * @author Sven Radej <radej@kde.org> * @short Class for group of radio butons in toolbar. */class KRadioGroup : public QObject{ Q_OBJECTpublic: /** * Constructor. Parent must be @ref KToolBar . */ KRadioGroup (QWidget *_parent, const char *_name=0); /** * Destructor. */ ~KRadioGroup () {}; /** * Adds button to group. Button cannot be unset by mouse clicks (you * must press some other button tounset this one) */ void addButton (int id); /** * Removes button from group, making it again toggle button (i.e. * You can unset it with mouse). */ void removeButton (int id);public slots: /** * Internal - nothing for you here. */ void slotToggled (int);private: QIntDict<KToolBarButton> buttons; KToolBar *tb;};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -