|
|
KToolBoxManager is a class for self management of small windows. Windows can be resized or moved. During move/resize it will emit all changes and you can recompute and accept or discard new geometry. You can define hot spots on the screen, and you will receive signal when your widget enters it. KToolBoxManager doesn't draw any decoration.
You will call (after constructing KToolBoxManager instance) doMove or doResize when mouse presses some handle point of your widget. Then, KToolBoxManager will move (or resize) hollow rectangle (or actual widget) on the screen. Moving/resizing is finished on mouse release event or by calling stop() function. Provided that your widget is top-level, the simplest use is like this:
mousePressevent(QMouseEvent *) { KToolBoxManager *mgr = new KToolBoxManager(this); doMove(); }
Moving/resizing can be transparent or opaque. In transparent mode, word "resizer" refers to hollow rectangle which is actually resized or moved. In opaque mode it refers to actual widget.
Moving child widgets in opaque mode will move the widget only inside your parent widget. You can drag it outside, but you won't see it, neither during drag nor after. You should reparent it in that case.
Functions doMove and doResize do not return untill mouse is released or stop() function is called. However, this is QTimer driven so you will receive signals, and Qt-engine will operate normally. Halting does not hog CPU (it's not an empty for(;;) loop).
You will not receive mouseRelease event when mouse is released. (uh.)
KToolBoxManager (QWidget *widget, bool transparent=true) |
Constructor. widget is the widget to be managed. It can be any custom widget with QWidget as a base class. If transparent is true (default) moving and resizing is transparent. doMove or doResize won't return till mouseRelease, or stop . Qt will run normaly, because this thing is QTimer driven. You can get position and size calling x , y , width and height
~KToolBoxManager () |
Destructor. If resizer is working, it will stop working, and move/resize the widget (i.e. will call stop) before it's death.
void doMove (bool in_hotspot_static=false, bool dynamic = false, bool dontmove=false) |
Starts moving. If dynamic is true signal posChanged will be emitted whenever position changes. If dynamic is false no signals are emitted except onHotSpot when resizer enters a hot spot area. Function will not return till end of drag. You can call setGeometry and resizer will adapt to it whenever you want. If dontmove is false, widget is moved to resizer's position when dragging If dontmove is false, no move is done you have to do it. Beware, moving of child widgets often isn't what you want. Still it is possible. If KToolBoxManager already moves or resizes widget when you call this function, it will return and do nothing.<br> When dynamic is true, signal posChanged is emitted when resizer changes position.<br> When in_hotspot_static is true, resizer is not moved while in hotspot; only mouse moves, and posChanged is not emitted. Hint: Call this function with dynamic=false and define hot spots.
void doResize (bool dynamic = false, bool dontresize=false) |
Starts resizing. If dynamic is true (default) signal sizeChanged will be emitted whenever size changes. If dynamic is false, no signals are emitted. Function will not return until button mouse is released or stop function is called. You can call setGeometry and resizer will adapt to it whenever you want. If dontresize is false, widget is resized to resizer's size on the end. If dontresize is true, widget is not resized, you have to do it. If KToolBoxManager already moves or resizes widget when you call this function, it will return and do nothing. When dynamic is true, signal sizeChanged is emitted only when resizers changes size. You can resize the resizer with setGeometry or resize . Note that (for know) KTBM can only resize on the right/bottom side of the widget.
void doXResize (bool dynamic = false, bool dontresize=false) |
Starts vertical only resizing. Arguments and behaviour are the same as in doMove .
void doYResize (bool dynamic = false, bool dontresize=false) |
Starts horizontal only resizing. Arguments and behaviour are the same as in doMove .
int addHotSpot (int x, int y, int w, int h) |
Adds region x, y, w, h to the lists of hot spots, and returns index of that hot spot. When resizer enters that hot spot, signal onHotSpot will be emitted. Only first hotspot is reported That mean if you have overlaping hotspots the one with the lower index will be reported. There is a special hotspot with index -1; exterior of all hotspots(the whole screen minus defined hotspots). When resizer leaves defined all hotspots onHotSpot (-1) will be emitted.
Note that x and y must be global screen coordinates.
int addHotSpot (const QRect &r, bool mapToGlobal=false) |
This is an overloaded function which takes rectangle as parameter. if mapToGlobal = true, rect will be converted to global coords.
void removeHotSpot (int index) |
Removes hot spot index.
void setGeometry (int x, int y, int w, int h) |
Sets geometry of resizer. Does nothing if manager is not working (i.e. if doMove or doResize were not called first). This function will not emit signals sizeChanged , posChanged or onHotSpot . Call this after you received some of those signals, and you have to change geometry. For example, toolbar will change geometry if dragged on hot spots - to tell user that it will - if left on that place - re-embed itself into parent window. Note that x and y must be global screen coordinates.
void setGeometry (int index) |
Sets geometry of resizer to geometry of hotspot index. This is provided for conevenience. Does nothing is index is false.
void resize (int rw, int rh) |
Resizes the resizer. rw is width and rh is height
int mouseX () |
Returns global x coordinate of a mouse.
int mouseY () |
Returns global y coordinate of a mouse.
int x () |
Returns global x coordinate of resizer.
int y () |
Returns global y coordinate of resizer.
int width () |
Returns width of resizer.
int height () |
Returns height resizer.
void stop () |
Calling this slot will stop the process of moving or resizing. It is equal as if user releases the mouse button.
void drawRectangle (int x, int y, int w, int h) |
Internal - draws rectangle on the screen
void deleteLastRectangle () |
Internal - deletes last rectangle, if there is one.
enum Mode {Nothing=0, Moving=1, Resizing=2} |
Internal - mode.
void doMoveInternal () |
Internal, QTimer driven mover.
void doResizeInternal () |
Internal, QTimer driven sizer.
void posChanged (int x, int y) |
This signal is emitted when resizer changes position. Note: x and y are global screen coordinates
void sizeChanged (int w, int h) |
This signal is emitted when resizer changes size.
void onHotSpot (int id) |
This signal is emitted when resizer enter hot spot index. It is also emited with index = -1 in the moment when resizer leaves a hot spot but doesn't enter another hotspot. That is, when it goes to "free space".