Changeset 10109 in vbox
- Timestamp:
- Jul 2, 2008 2:15:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUtils.h
r9438 r10109 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2008 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 26 26 /* Qt includes */ 27 27 #include <QMouseEvent> 28 #include <Q3ListView> 29 30 /** 31 * Simple ListView filter to disable unselecting all items by clicking in the 32 * unused area of the list (which is actually very annoying for the Single 33 * selection mode). 34 */ 35 class QIListViewSelectionPreserver : protected QObject 36 { 37 public: 38 39 QIListViewSelectionPreserver (QObject *parent, Q3ListView *alv) 40 : QObject (parent), lv (alv) 41 { 42 lv->viewport()->installEventFilter (this); 43 } 44 45 protected: 46 47 bool eventFilter (QObject * /* o */, QEvent *e) 48 { 49 if (e->type() == QEvent::MouseButtonPress || 50 e->type() == QEvent::MouseButtonRelease || 51 e->type() == QEvent::MouseButtonDblClick) 52 { 53 QMouseEvent *me = static_cast<QMouseEvent *> (e); 54 if (!lv->itemAt (me->pos())) 55 return true; 56 } 57 58 return false; 59 } 60 61 private: 62 63 Q3ListView *lv; 64 }; 65 66 /** 67 * Simple class that filters out presses and releases of the given key 68 * directed to a widget (the widget acts like if it would never handle 69 * this key). 70 */ 71 class QIKeyFilter : protected QObject 72 { 73 public: 74 75 QIKeyFilter (QObject *aParent, Qt::Key aKey) : QObject (aParent), mKey (aKey) {} 76 77 void watchOn (QObject *o) { o->installEventFilter (this); } 78 79 protected: 80 81 bool eventFilter (QObject * /*o*/, QEvent *e) 82 { 83 if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) 84 { 85 QKeyEvent *ke = static_cast<QKeyEvent *> (e); 86 if (ke->key() == mKey || 87 (mKey == Qt::Key_Enter && ke->key() == Qt::Key_Return)) 88 { 89 ke->ignore(); 90 return false; 91 } 92 } 93 94 return false; 95 } 96 97 Qt::Key mKey; 98 }; 28 #include <QWidget> 99 29 100 30 /** … … 108 38 public: 109 39 110 QIAltKeyFilter (QObject *aParent) : 40 QIAltKeyFilter (QObject *aParent) :QObject (aParent) {} 111 41 112 void watchOn (QObject * o) { o->installEventFilter (this); }42 void watchOn (QObject *aObject) { aObject->installEventFilter (this); } 113 43 114 44 protected: 115 45 116 bool eventFilter (QObject * /* o*/, QEvent *e)46 bool eventFilter (QObject * /* aObject */, QEvent *aEvent) 117 47 { 118 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease)48 if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease) 119 49 { 120 QKeyEvent * ke = static_cast<QKeyEvent *> (e);121 if ( ke->modifiers() & Qt::AltModifier)50 QKeyEvent *event = static_cast<QKeyEvent *> (aEvent); 51 if (event->modifiers() & Qt::AltModifier) 122 52 return true; 123 53 } … … 127 57 128 58 /** 129 * Watches the given widget and makes sure the minimum widget size set by the layout130 * manager does never get smaller than the previous minimum size set by the131 * layout manager. This way, widgets with dynamic contents (i.e. text on some132 * toggle buttons) will be able only to grow, never shrink, to avoid flicker133 * during alternate contents updates (Pause -> Resume -> Pause -> ...).134 *135 * @todo not finished136 */137 class QIConstraintKeeper : public QObject138 {139 Q_OBJECT140 141 public:142 143 QIConstraintKeeper (QWidget *aParent) : QObject (aParent)144 {145 aParent->setMinimumSize (aParent->size());146 aParent->installEventFilter (this);147 }148 149 private:150 151 bool eventFilter (QObject *aObject, QEvent *aEvent)152 {153 if (aObject == parent() && aEvent->type() == QEvent::Resize)154 {155 QResizeEvent *ev = static_cast<QResizeEvent *> (aEvent);156 QSize oldSize = ev->oldSize();157 QSize newSize = ev->size();158 int maxWidth = newSize.width() > oldSize.width() ?159 newSize.width() : oldSize.width();160 int maxHeight = newSize.height() > oldSize.height() ?161 newSize.height() : oldSize.height();162 if (maxWidth > oldSize.width() || maxHeight > oldSize.height())163 qobject_cast<QWidget *> (parent())->setMinimumSize (maxWidth, maxHeight);164 }165 return QObject::eventFilter (aObject, aEvent);166 }167 };168 169 /**170 59 * Simple class which simulates focus-proxy rule redirecting widget 171 * assigned shortcu rto desired widget.60 * assigned shortcut to desired widget. 172 61 */ 173 62 class QIFocusProxy : protected QObject
Note:
See TracChangeset
for help on using the changeset viewer.