- Timestamp:
- Jun 8, 2010 9:43:31 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/extensions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.cpp
r30022 r30087 110 110 #endif /* RT_OS_DARWIN */ 111 111 112 QISplitter::QISplitter(QWidget * aParent /* = 0 */)113 : QSplitter( aParent)114 , m Polished(false)112 QISplitter::QISplitter(QWidget *pParent /* = 0 */) 113 : QSplitter(pParent) 114 , m_fPolished(false) 115 115 , m_type(Shade) 116 { 117 qApp->installEventFilter (this); 116 #ifdef Q_WS_MAC 117 , m_fHandleGrabbed(false) 118 #endif /* Q_WS_MAC */ 119 { 120 qApp->installEventFilter(this); 118 121 } 119 122 120 123 QISplitter::QISplitter(Qt::Orientation orientation /* = Qt::Horizontal */, QWidget *pParent /* = 0 */) 121 124 : QSplitter(orientation, pParent) 122 , m Polished(false)125 , m_fPolished(false) 123 126 , m_type(Shade) 127 #ifdef Q_WS_MAC 128 , m_fHandleGrabbed(false) 129 #endif /* Q_WS_MAC */ 124 130 { 125 131 qApp->installEventFilter (this); 126 132 } 127 133 128 bool QISplitter::eventFilter(QObject * aWatched, QEvent *aEvent)129 { 130 if ( aWatched == handle(1))131 { 132 switch ( aEvent->type())134 bool QISplitter::eventFilter(QObject *pWatched, QEvent *pEvent) 135 { 136 if (pWatched == handle(1)) 137 { 138 switch (pEvent->type()) 133 139 { 134 140 case QEvent::MouseButtonDblClick: 135 restoreState (mBaseState);141 restoreState(m_baseState); 136 142 break; 137 143 default: … … 139 145 } 140 146 } 141 142 return QSplitter::eventFilter(aWatched, aEvent); 143 } 144 145 void QISplitter::showEvent(QShowEvent *aEvent) 146 { 147 if (!mPolished) 148 { 149 mPolished = true; 150 mBaseState = saveState(); 151 } 152 153 return QSplitter::showEvent(aEvent); 147 #ifdef Q_WS_MAC 148 /* Special handling on the Mac. Cause there the horizontal handle is only 1 149 * pixel wide, its hard to catch. Therefor we make some invisible area 150 * around the handle and forwarding the mouse events to the handle, if the 151 * user presses the left mouse button. */ 152 else if ( m_type == Native 153 && orientation() == Qt::Horizontal 154 && count() > 1 155 && qApp->activeWindow() == window()) 156 { 157 switch (pEvent->type()) 158 { 159 case QEvent::MouseButtonPress: 160 case QEvent::MouseMove: 161 { 162 const int margin = 3; 163 QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent); 164 for (int i=1; i < count(); ++i) 165 { 166 QWidget *pHandle = handle(i); 167 if ( pHandle 168 && pHandle != pWatched) 169 { 170 /* Create new mouse event with translated mouse positions. */ 171 QMouseEvent newME(pMouseEvent->type(), 172 pHandle->mapFromGlobal(pMouseEvent->globalPos()), 173 pMouseEvent->button(), 174 pMouseEvent->buttons(), 175 pMouseEvent->modifiers()); 176 /* Check if we hit the handle */ 177 bool fMarginHit = QRect(pHandle->mapToGlobal(QPoint(0, 0)), pHandle->size()).adjusted(-margin, 0, margin, 0).contains(pMouseEvent->globalPos()); 178 if (pEvent->type() == QEvent::MouseButtonPress) 179 { 180 /* If we have a handle position hit and the left 181 * button is pressed, start the grabbing. */ 182 if ( fMarginHit 183 && pMouseEvent->buttons().testFlag(Qt::LeftButton)) 184 { 185 m_fHandleGrabbed = true; 186 setCursor(Qt::SplitHCursor); 187 qApp->postEvent(pHandle, new QMouseEvent(newME)); 188 return true; 189 } 190 } 191 else if(pEvent->type() == QEvent::MouseMove) 192 { 193 /* If we are in the near of the handle or currently 194 * dragging, forward the mouse event. */ 195 if ( fMarginHit 196 || ( m_fHandleGrabbed 197 && pMouseEvent->buttons().testFlag(Qt::LeftButton))) 198 { 199 setCursor(Qt::SplitHCursor); 200 qApp->postEvent(pHandle, new QMouseEvent(newME)); 201 return true; 202 } 203 else 204 { 205 /* If not, reset the state. */ 206 m_fHandleGrabbed = false; 207 setCursor(Qt::ArrowCursor); 208 } 209 } 210 } 211 } 212 break; 213 } 214 case QEvent::WindowDeactivate: 215 case QEvent::MouseButtonRelease: 216 { 217 m_fHandleGrabbed = false; 218 setCursor(Qt::ArrowCursor); 219 break; 220 } 221 default: 222 break; 223 } 224 } 225 #endif /* Q_WS_MAC */ 226 227 return QSplitter::eventFilter(pWatched, pEvent); 228 } 229 230 void QISplitter::showEvent(QShowEvent *pEvent) 231 { 232 if (!m_fPolished) 233 { 234 m_fPolished = true; 235 m_baseState = saveState(); 236 } 237 238 return QSplitter::showEvent(pEvent); 154 239 } 155 240 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QISplitter.h
r30022 r30087 31 31 enum Type { Native, Shade }; 32 32 33 QISplitter(QWidget * aParent = 0);33 QISplitter(QWidget *pParent = 0); 34 34 QISplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget *pParent = 0); 35 35 36 36 void setHandleType(Type type) { m_type = type; } 37 37 Type handleType() const { return m_type; } 38 private:39 38 40 bool eventFilter(QObject *aWatched, QEvent *aEvent); 41 void showEvent(QShowEvent *aEvent); 39 protected: 40 41 bool eventFilter(QObject *pWatched, QEvent *pEvent); 42 void showEvent(QShowEvent *pEvent); 42 43 43 44 QSplitterHandle* createHandle(); 44 45 45 QByteArray mBaseState; 46 private: 46 47 47 bool mPolished; 48 QByteArray m_baseState; 49 50 bool m_fPolished; 48 51 Type m_type; 52 #ifdef Q_WS_MAC 53 bool m_fHandleGrabbed; 54 #endif /* Q_WS_MAC */ 49 55 }; 50 56
Note:
See TracChangeset
for help on using the changeset viewer.