Changeset 17108 in vbox for trunk/src/VBox
- Timestamp:
- Feb 25, 2009 1:28:47 AM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/QIMessageBox.h
r16913 r17108 45 45 class QVBoxLayout; 46 46 47 /** @class QIArrowButton 48 * 49 * The QIArrowButton class is an arrow tool-botton with text-label. 50 * It is declared here until moved into separate file in case 51 * of it will be used somewhere except problem-reporter dialog. 52 */ 53 class QIArrowButton : public QWidget 54 { 55 Q_OBJECT; 56 57 public: 58 59 QIArrowButton (const QString &aName, QWidget *aParent = 0); 60 61 bool isExpanded() const; 62 63 void animateClick(); 64 65 signals: 66 67 void clicked(); 68 69 private slots: 70 71 void buttonClicked(); 72 73 private: 74 75 void updateIcon(); 76 77 bool eventFilter (QObject *aObject, QEvent *aEvent); 78 79 void paintEvent (QPaintEvent *aEvent); 80 81 bool mIsExpanded; 82 QToolButton *mButton; 83 QLabel *mLabel; 84 }; 85 47 86 /** @class QIArrowSplitter 48 87 * … … 57 96 public: 58 97 59 enum ToggleType60 {61 Toggle = 0,62 CollapsOnly,63 ExpandOnly64 };65 66 98 QIArrowSplitter (QWidget *aParent = 0); 67 99 … … 70 102 public slots: 71 103 72 void toggleWidget (ToggleType aType = Toggle);104 void toggleWidget(); 73 105 74 106 private: … … 77 109 78 110 QVBoxLayout *mMainLayout; 79 QList <Q ToolButton*> mButtonsList;111 QList <QIArrowButton*> mButtonsList; 80 112 QList <QWidget*> mWidgetsList; 81 113 }; -
trunk/src/VBox/Frontends/VirtualBox/src/QIMessageBox.cpp
r16956 r17108 35 35 #include <QLabel> 36 36 #include <QPushButton> 37 #include <QStyleOptionFocusRect> 38 #include <QStylePainter> 37 39 #include <QToolButton> 40 41 /** @class QIArrowButton 42 * 43 * The QIArrowButton class is an arrow tool-botton with text-label. 44 */ 45 QIArrowButton::QIArrowButton (const QString &aName, QWidget *aParent) 46 : QWidget (aParent) 47 , mIsExpanded (false) 48 , mButton (new QToolButton()) 49 , mLabel (new QLabel (aName)) 50 { 51 /* Setup itself */ 52 setFocusPolicy (Qt::StrongFocus); 53 54 /* Setup tool-button */ 55 mButton->setAutoRaise (true); 56 mButton->setFixedSize (14, 16); 57 mButton->setFocusPolicy (Qt::NoFocus); 58 mButton->setStyleSheet ("QToolButton {border: 0px none black;}"); 59 connect (mButton, SIGNAL (clicked (bool)), this, SLOT (buttonClicked())); 60 updateIcon(); 61 62 /* Setup text-label */ 63 mLabel->setBuddy (mButton); 64 mLabel->setStyleSheet ("QLabel {padding: 0px 1px 0px 1px;}"); 65 66 /* Setup main-layout */ 67 QHBoxLayout *mainLayout = new QHBoxLayout (this); 68 VBoxGlobal::setLayoutMargin (mainLayout, 0); 69 mainLayout->addWidget (mButton); 70 mainLayout->addWidget (mLabel); 71 mainLayout->addStretch(); 72 73 /* Install event-filter */ 74 qApp->installEventFilter (this); 75 } 76 77 bool QIArrowButton::isExpanded() const 78 { 79 return mIsExpanded; 80 } 81 82 void QIArrowButton::animateClick() 83 { 84 mButton->animateClick(); 85 } 86 87 void QIArrowButton::buttonClicked() 88 { 89 mIsExpanded = !mIsExpanded; 90 updateIcon(); 91 emit clicked(); 92 } 93 94 void QIArrowButton::updateIcon() 95 { 96 mButton->setIcon (VBoxGlobal::iconSet (mIsExpanded ? 97 ":/arrow_down_10px.png" : ":/arrow_right_10px.png")); 98 } 99 100 bool QIArrowButton::eventFilter (QObject *aObject, QEvent *aEvent) 101 { 102 /* Process only QIArrowButton or children */ 103 if (!(aObject == this || children().contains (aObject))) 104 return QWidget::eventFilter (aObject, aEvent); 105 106 /* Process some keyboard events */ 107 if (aEvent->type() == QEvent::KeyPress) 108 { 109 QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent); 110 switch (kEvent->key()) 111 { 112 /* "+" as expand */ 113 case Qt::Key_Plus: 114 { 115 if (!mIsExpanded) 116 mButton->animateClick(); 117 break; 118 } 119 /* "-" as collapse */ 120 case Qt::Key_Minus: 121 { 122 if (mIsExpanded) 123 mButton->animateClick(); 124 break; 125 } 126 /* Space as toggle */ 127 case Qt::Key_Space: 128 { 129 mButton->animateClick(); 130 break; 131 } 132 } 133 } 134 135 /* Process some mouse events */ 136 if ((aEvent->type() == QEvent::MouseButtonPress || 137 aEvent->type() == QEvent::MouseButtonDblClick) 138 && aObject == mLabel) 139 { 140 /* Label click as toggle */ 141 mButton->animateClick(); 142 } 143 144 /* Default one handler */ 145 return QWidget::eventFilter (aObject, aEvent); 146 } 147 148 void QIArrowButton::paintEvent (QPaintEvent *aEvent) 149 { 150 if (hasFocus()) 151 { 152 QStylePainter painter (this); 153 QStyleOptionFocusRect option; 154 option.initFrom (this); 155 option.rect = mLabel->frameGeometry(); 156 painter.drawPrimitive (QStyle::PE_FrameFocusRect, option); 157 } 158 QWidget::paintEvent (aEvent); 159 } 38 160 39 161 /** @class QIArrowSplitter … … 45 167 , mMainLayout (new QVBoxLayout (this)) 46 168 { 169 /* Setup main-layout */ 47 170 VBoxGlobal::setLayoutMargin (mMainLayout, 0); 171 172 /* Install event-filter */ 48 173 qApp->installEventFilter (this); 49 174 } … … 51 176 void QIArrowSplitter::addWidget (const QString &aName, QWidget *aWidget) 52 177 { 53 /* Creating arrow tool-button */ 54 QToolButton *arrowButton = new QToolButton(); 55 connect (arrowButton, SIGNAL (clicked (bool)), this, SLOT (toggleWidget())); 56 arrowButton->setIcon (VBoxGlobal::iconSet (":/arrow_right_10px.png")); 57 arrowButton->setFocusPolicy (Qt::StrongFocus); 58 arrowButton->setAutoRaise (true); 59 arrowButton->setFixedSize (14, 16); 60 arrowButton->setStyleSheet ("QToolButton { border: 0px none black; }"); 61 mButtonsList.append (arrowButton); 62 63 /* Creating description label */ 64 QLabel *descriptionLabel = new QLabel (aName); 65 descriptionLabel->setBuddy (arrowButton); 66 178 /* Creating arrow button */ 179 QIArrowButton *button = new QIArrowButton (aName); 180 connect (button, SIGNAL (clicked()), this, SLOT (toggleWidget())); 181 182 /* Append internal lists */ 183 mButtonsList.append (button); 67 184 mWidgetsList.append (aWidget); 68 185 69 QHBoxLayout *lineLayout = new QHBoxLayout(); 70 lineLayout->addWidget (arrowButton); 71 lineLayout->addWidget (descriptionLabel); 72 73 mMainLayout->insertWidget (0, aWidget); 74 mMainLayout->insertLayout (0, lineLayout); 75 } 76 77 void QIArrowSplitter::toggleWidget (ToggleType aType) 78 { 79 QToolButton *arrowButton = qobject_cast <QToolButton*> (sender()); 80 81 /* Toggle all or the specified arrow & related widget */ 82 foreach (QToolButton *itemButton, mButtonsList) 83 { 84 if ((itemButton == arrowButton) || (!arrowButton)) 186 /* Append layout with children */ 187 mMainLayout->addWidget (button); 188 mMainLayout->addWidget (aWidget); 189 } 190 191 void QIArrowSplitter::toggleWidget() 192 { 193 QIArrowButton *clickedButton = qobject_cast <QIArrowButton*> (sender()); 194 195 foreach (QIArrowButton *button, mButtonsList) 196 { 197 if ((button == clickedButton) || !clickedButton) 85 198 { 86 QWidget *relatedWidget = mWidgetsList [mButtonsList.indexOf ( itemButton)];199 QWidget *relatedWidget = mWidgetsList [mButtonsList.indexOf (button)]; 87 200 Assert (relatedWidget); 88 if ((relatedWidget->isVisible() && aType != ExpandOnly) || 89 (!relatedWidget->isVisible() && aType != CollapsOnly)) 90 { 91 relatedWidget->setVisible (!relatedWidget->isVisible()); 92 itemButton->setIcon (VBoxGlobal::iconSet (relatedWidget->isVisible() ? 93 ":/arrow_down_10px.png" : ":/arrow_right_10px.png")); 94 } 201 relatedWidget->setVisible (button->isExpanded()); 95 202 } 96 203 } … … 110 217 /* Now resize window to minimum possible size */ 111 218 window()->resize (window()->minimumSizeHint()); 112 qApp->processEvents();113 #ifdef Q_WS_WIN114 /* Set fixed size to which one current we have */115 window()->setFixedSize (window()->size());116 #else117 /* Unable to resize on some platforms because it was fixed already */118 window()->setFixedSize (window()->minimumSizeHint());119 #endif120 219 } 121 220 122 221 bool QIArrowSplitter::eventFilter (QObject *aObject, QEvent *aEvent) 123 222 { 124 if (!aObject->isWidgetType()) 223 /* Process only parent window children */ 224 if (!(aObject == window() || window()->children().contains (aObject))) 125 225 return QWidget::eventFilter (aObject, aEvent); 126 226 127 QWidget *widget = qobject_cast <QWidget*> (aObject); 128 if (widget->window() != window()) 129 return QWidget::eventFilter (aObject, aEvent); 227 /* Do not process QIArrowButton children */ 228 foreach (QIArrowButton *button, mButtonsList) 229 if (button->children().contains (aObject)) 230 return QWidget::eventFilter (aObject, aEvent); 130 231 131 232 /* Process some keyboard events */ … … 133 234 { 134 235 QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent); 135 QToolButton *arrowButton = qobject_cast <QToolButton*> (QApplication::focusWidget());136 int slot = arrowButton ? mButtonsList.indexOf (arrowButton) : -1;137 236 switch (kEvent->key()) 138 237 { 139 238 case Qt::Key_Plus: 140 239 { 141 if (slot != -1 && !mWidgetsList [slot]->isVisible()) 142 arrowButton->animateClick(); 143 else 144 toggleWidget (ExpandOnly); 240 foreach (QIArrowButton *button, mButtonsList) 241 if (!button->isExpanded()) 242 button->animateClick(); 145 243 break; 146 244 } 147 245 case Qt::Key_Minus: 148 246 { 149 if (slot != -1 && mWidgetsList [slot]->isVisible()) 150 arrowButton->animateClick(); 151 else 152 toggleWidget (CollapsOnly); 247 foreach (QIArrowButton *button, mButtonsList) 248 if (button->isExpanded()) 249 button->animateClick(); 153 250 break; 154 251 } … … 156 253 } 157 254 255 /* Default one handler */ 158 256 return QWidget::eventFilter (aObject, aEvent); 159 257 } … … 510 608 mTextLabel->setMinimumWidth (mTextLabel->width()); 511 609 mTextLabel->updateSizeHint(); 610 qApp->processEvents(); 611 setFixedWidth (width()); 512 612 mDetailsSplitter->toggleWidget(); 513 613 mWasPolished = true;
Note:
See TracChangeset
for help on using the changeset viewer.