![]() |
Home · All Namespaces · All Classes |
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of systemui. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 #include <QGraphicsSceneMouseEvent> 00020 #include <MSceneManager> 00021 #include <MSceneWindow> 00022 #include <MApplicationExtensionArea> 00023 #include <MEscapeButtonPanel> 00024 #include <MButton> 00025 #include <MOverlay> 00026 #include <MPannableViewport> 00027 #include <QGraphicsLinearLayout> 00028 #include <MWidgetView> 00029 #include "notificationarea.h" 00030 #include <MViewCreator> 00031 #include <mstatusbar.h> 00032 #include <QGraphicsAnchorLayout> 00033 #include <QTimer> 00034 #include "statusindicatormenu.h" 00035 #include "statusindicatormenudropdownview.h" 00036 #include "statusindicatormenustyle.h" 00037 00038 const int StatusIndicatorMenuDropDownView::VIEW_INITIALIZATION_DELAY = 30 * 1000; 00039 00040 00041 void EventEaterWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) 00042 { 00043 event->accept(); 00044 } 00045 00046 PannedWidgetController::PannedWidgetController(QGraphicsItem *parent) : 00047 MWidgetController(parent), 00048 bottommostWidget_(NULL) 00049 { 00050 } 00051 00052 const QGraphicsWidget *PannedWidgetController::bottommostWidget() const 00053 { 00054 return bottommostWidget_; 00055 } 00056 00057 void PannedWidgetController::setBottommostWidget(const QGraphicsWidget *widget) 00058 { 00059 bottommostWidget_ = widget; 00060 } 00061 00062 void PannedWidgetController::setGeometry(const QRectF &rect) 00063 { 00064 MWidgetController::setGeometry(rect); 00065 emit positionOrSizeChanged(); 00066 } 00067 00068 void PannedWidgetController::mousePressEvent(QGraphicsSceneMouseEvent *event) 00069 { 00070 event->accept(); 00071 } 00072 00073 void PannedWidgetController::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) 00074 { 00075 if (bottommostWidget_) { 00076 // Test that the y position of the event is bigger than the bottom edge of the bottommost widget. 00077 // The calculations are done in this widget's coordinate space. 00078 if (event->pos().y() > bottommostWidget_->y() + bottommostWidget_->geometry().height()) { 00079 emit pressedOutSideContents(); 00080 } 00081 } 00082 } 00083 00084 StatusIndicatorMenuDropDownView::StatusIndicatorMenuDropDownView(StatusIndicatorMenu *controller) : 00085 MSceneWindowView(controller), 00086 controller(controller), 00087 statusBar(new MStatusBar), 00088 settingsPluginsExtensionArea(NULL), 00089 statusIndicatorExtensionArea(NULL), 00090 pannableViewport(NULL), 00091 closeButtonOverlay(NULL), 00092 backgroundWidget(new MWidgetController) 00093 { 00094 // Show status bar 00095 controller->sceneManager()->appearSceneWindowNow(statusBar); 00096 00097 // Create close button overlay 00098 closeButtonOverlay = createCloseButtonOverlay(); 00099 00100 // Create the pannable area background widget 00101 backgroundWidget->setView(new MWidgetView(backgroundWidget)); 00102 backgroundWidget->setObjectName("StatusIndicatorMenuWindowBackground"); 00103 00104 connect(controller, SIGNAL(hideRequested()), this, SLOT(resetViewport())); 00105 connect(controller, SIGNAL(displayEntered()), SLOT(ensureIsViewable())); 00106 00107 // Schedule the view to be initialized 00108 QTimer::singleShot(VIEW_INITIALIZATION_DELAY, this, SLOT(ensureIsViewable())); 00109 } 00110 00111 00112 StatusIndicatorMenuDropDownView::~StatusIndicatorMenuDropDownView() 00113 { 00114 delete backgroundWidget; 00115 delete statusBar; 00116 delete closeButtonOverlay; 00117 delete pannableViewport; 00118 delete topRowWidget; 00119 } 00120 00121 QGraphicsWidget* StatusIndicatorMenuDropDownView::createTopRow() 00122 { 00123 // Create an extension area for the top row plugins 00124 settingsPluginsExtensionArea = new MApplicationExtensionArea("com.meego.core.MStatusIndicatorMenuExtensionInterface/1.0"); 00125 connect(settingsPluginsExtensionArea, SIGNAL(extensionInstantiated(MApplicationExtensionInterface*)), controller, SLOT(setStatusIndicatorMenuInterface(MApplicationExtensionInterface*))); 00126 settingsPluginsExtensionArea->setObjectName("StatusIndicatorMenuTopRowExtensionArea"); 00127 settingsPluginsExtensionArea->setInProcessFilter(QRegExp("/statusindicatormenu-(alarms|internetconnection|presence|profile).desktop$")); 00128 settingsPluginsExtensionArea->setOutOfProcessFilter(QRegExp("$^")); 00129 settingsPluginsExtensionArea->setOrder((QStringList() << "statusindicatormenu-alarms.desktop" << "statusindicatormenu-internetconnection.desktop" << "statusindicatormenu-presence.desktop" << "statusindicatormenu-profile.desktop")); 00130 00131 // Create a button for accessing the full settings 00132 //% "Settings" 00133 MButton *settingsButton = new MButton(qtTrId("qtn_stat_menu_settings")); 00134 settingsButton->setObjectName("StatusIndicatorMenuTopRowExtensionButton"); 00135 settingsButton->setViewType(MButton::iconType); 00136 settingsButton->setIconID("icon-m-status-menu-settings"); 00137 connect(settingsButton, SIGNAL(clicked()), controller, SLOT(launchControlPanelAndHide())); 00138 00139 // Put the extension area and the settings button to a horizontal layout 00140 QGraphicsLinearLayout *topRowLayout = new QGraphicsLinearLayout(Qt::Horizontal); 00141 topRowLayout->setContentsMargins(0, 0, 0, 0); 00142 topRowLayout->setSpacing(0); 00143 topRowLayout->addStretch(); 00144 topRowLayout->addItem(settingsPluginsExtensionArea); 00145 topRowLayout->addItem(settingsButton); 00146 topRowLayout->addStretch(); 00147 00148 // Create a container widget for extension area and settings button layout 00149 MWidgetController *topRowWidget = new MWidgetController; 00150 topRowWidget->setView(new MWidgetView(topRowWidget)); 00151 topRowWidget->setObjectName("StatusIndicatorMenuExtensionAreaWidget"); 00152 topRowWidget->setLayout(topRowLayout); 00153 00154 return topRowWidget; 00155 } 00156 00157 MApplicationExtensionArea* StatusIndicatorMenuDropDownView::createVerticalExtensionArea() 00158 { 00159 // Create an extension area for the call ui and transfer ui plugins 00160 MApplicationExtensionArea *extensionArea = new MApplicationExtensionArea("com.meego.core.MStatusIndicatorMenuExtensionInterface/1.0"); 00161 extensionArea->setObjectName("StatusIndicatorMenuVerticalExtensionArea"); 00162 extensionArea->setInProcessFilter(QRegExp("/statusindicatormenu-(call|transfer).desktop$")); 00163 extensionArea->setOutOfProcessFilter(QRegExp("$^")); 00164 extensionArea->setOrder((QStringList() << "statusindicatormenu-call.desktop" << "statusindicatormenu-transfer.desktop")); 00165 connect(extensionArea, SIGNAL(extensionInstantiated(MApplicationExtensionInterface*)), controller, SLOT(setStatusIndicatorMenuInterface(MApplicationExtensionInterface*))); 00166 return extensionArea; 00167 } 00168 00169 MPannableViewport* StatusIndicatorMenuDropDownView::createPannableArea() 00170 { 00171 // Create pannable area contents 00172 statusIndicatorExtensionArea = createVerticalExtensionArea(); 00173 00174 QGraphicsLinearLayout *contentLayout = new QGraphicsLinearLayout(Qt::Vertical); 00175 contentLayout->setContentsMargins(0, 0, 0, 0); 00176 contentLayout->setSpacing(0); 00177 contentLayout->addItem(statusIndicatorExtensionArea); 00178 00179 if(style()->notificationArea()) { 00180 NotificationArea *notificationArea = new NotificationArea; 00181 connect(notificationArea, SIGNAL(bannerClicked()), controller, SIGNAL(hideRequested())); 00182 contentLayout->addItem(notificationArea); 00183 } 00184 00185 MWidgetController *contentWidget = new MWidgetController; 00186 contentWidget->setView(new MWidgetView(contentWidget)); 00187 contentWidget->setObjectName("StatusIndicatorMenuContentWidget"); 00188 contentWidget->setLayout(contentLayout); 00189 00190 QGraphicsLinearLayout *pannableLayout = new QGraphicsLinearLayout(Qt::Vertical); 00191 pannableLayout->setContentsMargins(0, 0, 0, 0); 00192 pannableLayout->setSpacing(0); 00193 pannableLayout->addItem(contentWidget); 00194 QGraphicsWidget *closeButtonRow = createCloseButtonRow(); 00195 pannableLayout->addItem(closeButtonRow); 00196 pannableLayout->addStretch(); 00197 00198 // Create a container widget for the pannable area 00199 PannedWidgetController *pannedWidget = new PannedWidgetController; 00200 pannedWidget->setView(new MWidgetView(pannedWidget)); 00201 pannedWidget->setLayout(pannableLayout); 00202 pannedWidget->setBottommostWidget(closeButtonRow); 00203 connect(pannedWidget, SIGNAL(positionOrSizeChanged()), this, SLOT(setPannabilityAndLayout())); 00204 connect(pannedWidget, SIGNAL(pressedOutSideContents()), controller, SIGNAL(hideRequested())); 00205 00206 // Setup the pannable viewport 00207 MPannableViewport *pannableViewport = new MPannableViewport; 00208 pannableViewport->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 00209 pannableViewport->setWidget(pannedWidget); 00210 return pannableViewport; 00211 } 00212 00213 QGraphicsWidget* StatusIndicatorMenuDropDownView::createCloseButtonRow() 00214 { 00215 // Create a close button for the pannable area 00216 MButton *closeButton = new MButton; 00217 closeButton->setViewType("icon"); 00218 closeButton->setObjectName("StatusIndicatorMenuCloseButton"); 00219 closeButton->setIconID("icon-m-framework-close"); 00220 connect(closeButton, SIGNAL(clicked()), controller, SIGNAL(hideRequested())); 00221 00222 // Add two overlay widgets that will not allow mouse events to pass through them next to the close button 00223 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal); 00224 layout->setContentsMargins(0, 0, 0, 0); 00225 layout->setSpacing(0); 00226 layout->addItem(new EventEaterWidget); 00227 layout->addItem(closeButton); 00228 layout->addItem(new EventEaterWidget); 00229 00230 // Create the area itself 00231 MWidgetController *closeButtonArea = new MWidgetController; 00232 closeButtonArea->setView(new MWidgetView(closeButtonArea)); 00233 closeButtonArea->setObjectName("CloseButtonArea"); 00234 closeButtonArea->setLayout(layout); 00235 00236 return closeButtonArea; 00237 } 00238 00239 MOverlay *StatusIndicatorMenuDropDownView::createCloseButtonOverlay() 00240 { 00241 // Create a close button 00242 MButton *closeButton = new MButton; 00243 closeButton->setViewType("icon"); 00244 closeButton->setObjectName("StatusIndicatorMenuCloseButton"); 00245 closeButton->setIconID("icon-m-framework-close"); 00246 connect(closeButton, SIGNAL(clicked()), controller, SIGNAL(hideRequested())); 00247 00248 // Add two overlay widgets that will not allow mouse events to pass through them next to the close button 00249 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal); 00250 layout->setContentsMargins(0, 0, 0, 0); 00251 layout->setSpacing(0); 00252 layout->addItem(new EventEaterWidget); 00253 layout->addItem(closeButton); 00254 layout->addItem(new EventEaterWidget); 00255 00256 // Create the overlay itself 00257 MOverlay *closeButtonOverlay = new MOverlay; 00258 closeButtonOverlay->setLayout(layout); 00259 closeButtonOverlay->setObjectName("CloseButtonOverlay"); 00260 controller->sceneManager()->appearSceneWindowNow(closeButtonOverlay); 00261 controller->sceneManager()->disappearSceneWindowNow(closeButtonOverlay); 00262 00263 return closeButtonOverlay; 00264 } 00265 00266 void StatusIndicatorMenuDropDownView::ensureIsViewable() 00267 { 00268 settingsPluginsExtensionArea->init(); 00269 00270 if (statusIndicatorExtensionArea) { 00271 statusIndicatorExtensionArea->init(); 00272 } 00273 } 00274 00275 void StatusIndicatorMenuDropDownView::setPannabilityAndLayout() 00276 { 00277 QGraphicsWidget *pannableWidget = pannableViewport->widget(); 00278 00279 // Enable pannability if there is too much content to fit on the screen 00280 bool viewportShouldBePannable = pannableWidget->effectiveSizeHint(Qt::PreferredSize).height() > pannableViewport->geometry().height(); 00281 pannableViewport->setEnabled(viewportShouldBePannable); 00282 00283 // Appear or disappear the close button overlay based on close area position 00284 const QGraphicsWidget *closeButtonRow = static_cast<PannedWidgetController *>(pannableViewport->widget())->bottommostWidget(); 00285 qreal screenHeight = controller->sceneManager()->visibleSceneSize().height(); 00286 qreal closeButtonRowBottomYPos = closeButtonRow->mapToItem(controller, QPointF(0, closeButtonRow->geometry().height())).y(); 00287 00288 if (closeButtonRowBottomYPos <= screenHeight) { 00289 controller->sceneManager()->disappearSceneWindowNow(closeButtonOverlay); 00290 } else { 00291 controller->sceneManager()->appearSceneWindowNow(closeButtonOverlay); 00292 } 00293 00294 // Make the pannable area background window extend from the top of the pannable viewport halfway to the bottom of the close button row 00295 qreal viewPortYPos = pannableViewport->mapToItem(controller, QPointF()).y(); 00296 qreal backgroundHeight = (closeButtonRowBottomYPos - viewPortYPos) / 2; 00297 if (backgroundHeight < 0) { 00298 backgroundHeight = 0; 00299 } 00300 backgroundWidget->setMinimumHeight(backgroundHeight); 00301 backgroundWidget->setMaximumHeight(backgroundHeight); 00302 } 00303 00304 void StatusIndicatorMenuDropDownView::resetViewport() 00305 { 00306 pannableViewport->setPosition(QPointF(0,0)); 00307 } 00308 00309 void StatusIndicatorMenuDropDownView::applyStyle() 00310 { 00311 MWidgetView::applyStyle(); 00312 00313 if (pannableViewport == NULL) { 00314 QGraphicsAnchorLayout *backgroundLayout = new QGraphicsAnchorLayout; 00315 backgroundLayout->setContentsMargins(0, 0, 0, 0); 00316 backgroundLayout->setSpacing(0); 00317 backgroundLayout->addCornerAnchors(backgroundWidget, Qt::TopLeftCorner, backgroundLayout, Qt::TopLeftCorner); 00318 backgroundLayout->setMaximumHeight(0); 00319 00320 // Put all the stuff into the scene window layout 00321 pannableViewport = createPannableArea(); 00322 topRowWidget = createTopRow(); 00323 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); 00324 layout->setContentsMargins(0, 0, 0, 0); 00325 layout->setSpacing(0); 00326 layout->addItem(topRowWidget); 00327 layout->addItem(backgroundLayout); 00328 layout->addItem(pannableViewport); 00329 controller->setLayout(layout); 00330 } 00331 } 00332 00333 M_REGISTER_VIEW_NEW(StatusIndicatorMenuDropDownView, StatusIndicatorMenu)
| Copyright © 2010 Nokia Corporation | Generated on Wed Nov 10 16:04:52 2010 Doxygen 1.6.1 |
MeeGo Touch |
