From: Sami Rämö Date: Fri, 3 Sep 2010 10:12:12 +0000 (+0300) Subject: Merge branch 'master' into context_driven_buttons, review X-Git-Tag: v2.0b-1~17^2 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=41c63e3292ebb059a9dcff52aa8335cdee9f2e78;hp=c16c23c97901ec289a566ae0c13f5271c573ba40;p=situare Merge branch 'master' into context_driven_buttons, review - Reviewed by Jussi Laitinen Conflicts: images.qrc src/src.pro src/ui/friendlistpanel.cpp src/ui/locationsearchpanel.cpp --- diff --git a/images.qrc b/images.qrc index b033893..3dc6593 100644 --- a/images.qrc +++ b/images.qrc @@ -60,6 +60,9 @@ res/images/zoom_in.png res/images/zoom_out.png res/images/location_search.png + res/images/list_item_context_button_bar_left.png + res/images/list_item_context_button_bar_right.png + res/images/list_item_context_button_bar_tile.png res/images/search_history.png res/images/clear_btn_d.png res/images/clear_btn_s.png diff --git a/res/images/list_item_context_button_bar_left.png b/res/images/list_item_context_button_bar_left.png new file mode 100644 index 0000000..4eb44c1 Binary files /dev/null and b/res/images/list_item_context_button_bar_left.png differ diff --git a/res/images/list_item_context_button_bar_right.png b/res/images/list_item_context_button_bar_right.png new file mode 100644 index 0000000..3eb816b Binary files /dev/null and b/res/images/list_item_context_button_bar_right.png differ diff --git a/res/images/list_item_context_button_bar_tile.png b/res/images/list_item_context_button_bar_tile.png new file mode 100644 index 0000000..2bf223b Binary files /dev/null and b/res/images/list_item_context_button_bar_tile.png differ diff --git a/src/src.pro b/src/src.pro index 6c35bb4..8cc801c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -85,7 +85,8 @@ SOURCES += main.cpp \ ui/userinfopanel.cpp \ ui/zoombutton.cpp \ ui/zoombuttonpanel.cpp \ - user/user.cpp + user/user.cpp \ + ui/listitemcontextbuttonbar.cpp HEADERS += application.h \ common.h \ coordinates/geocoordinate.h \ @@ -172,7 +173,8 @@ HEADERS += application.h \ ui/userinfopanel.h \ ui/zoombutton.h \ ui/zoombuttonpanel.h \ - user/user.h + user/user.h \ + ui/listitemcontextbuttonbar.h QT += network \ webkit DEFINES += QT_NO_DEBUG_OUTPUT diff --git a/src/ui/friendlistpanel.cpp b/src/ui/friendlistpanel.cpp index d8740af..99a2585 100644 --- a/src/ui/friendlistpanel.cpp +++ b/src/ui/friendlistpanel.cpp @@ -84,7 +84,7 @@ FriendListPanel::FriendListPanel(QWidget *parent) this, SIGNAL(findFriend(GeoCoordinate))); connect(m_friendListView, SIGNAL(listItemSelectionChanged()), - this, SLOT(setRouteButtonDisabled())); + this, SLOT(onListItemSelectionChanged())); // --- FOOTER, TEXT BASED FILTERING --- QHBoxLayout *footerLayout = new QHBoxLayout(); @@ -122,7 +122,6 @@ FriendListPanel::FriendListPanel(QWidget *parent) m_routeButton = new ImageButton(":res/images/route_to_friend.png", ":res/images/route_to_friend_s.png", ":res/images/route_to_friend_d.png", this); - m_routeButton->setDisabled(true); connect(m_routeButton, SIGNAL(clicked()), this, SLOT(routeToSelectedFriend())); @@ -140,9 +139,9 @@ FriendListPanel::FriendListPanel(QWidget *parent) connect(m_clearGroupFilteringButton, SIGNAL(clicked()), this, SLOT(clearFiltering())); - m_contextButtonLayout->addWidget(m_routeButton); - m_contextButtonLayout->addWidget(m_showContactButton); - m_contextButtonLayout->addWidget(m_clearGroupFilteringButton); + m_itemButtonsLayout->addWidget(m_routeButton); + m_itemButtonsLayout->addWidget(m_showContactButton); + m_genericButtonsLayout->addWidget(m_clearGroupFilteringButton); } void FriendListPanel::anyPanelClosed() @@ -155,7 +154,6 @@ void FriendListPanel::anyPanelClosed() clearFiltering(); m_friendListView->clearItemSelection(); - setRouteButtonDisabled(); } void FriendListPanel::anyPanelOpened() @@ -244,7 +242,6 @@ void FriendListPanel::hideEvent(QHideEvent *event) clearFiltering(); m_friendListView->clearItemSelection(); - setRouteButtonDisabled(); } void FriendListPanel::requestSelectedFriendContactDialog() @@ -291,13 +288,6 @@ void FriendListPanel::updateKeyboardGrabbing() } } -void FriendListPanel::setRouteButtonDisabled() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_routeButton->setDisabled(m_friendListView->selectedItems().isEmpty()); -} - void FriendListPanel::showEvent(QShowEvent *event) { qDebug() << __PRETTY_FUNCTION__; diff --git a/src/ui/friendlistpanel.h b/src/ui/friendlistpanel.h index 71aeeab..43362a1 100644 --- a/src/ui/friendlistpanel.h +++ b/src/ui/friendlistpanel.h @@ -174,13 +174,6 @@ private slots: void routeToSelectedFriend(); /** - * @brief Sets route button disabled. - * - * Disabled if there isn't any list item selected. - */ - void setRouteButtonDisabled(); - - /** * @brief Slot to show friends in list. * * Shows only friends that are on userIDs list diff --git a/src/ui/listitemcontextbuttonbar.cpp b/src/ui/listitemcontextbuttonbar.cpp new file mode 100644 index 0000000..d7b6551 --- /dev/null +++ b/src/ui/listitemcontextbuttonbar.cpp @@ -0,0 +1,187 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include +#include +#include +#include + +#include "panelcommon.h" + +#include "listitemcontextbuttonbar.h" + +ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) : + QWidget(parent), + m_waitForOpen(false), + m_contextButtons(0), + m_newContextButtons(0), + m_state(StateHidden) +{ + qDebug() << __PRETTY_FUNCTION__; + + // --- BAR LOOK --- + const int BAR_HEIGHT = 78; + setFixedHeight(BAR_HEIGHT); + + m_backgroundLeft = new QPixmap(":/res/images/list_item_context_button_bar_left.png"); + m_backgroundMiddle = new QPixmap(":/res/images/list_item_context_button_bar_tile.png"); + m_backgroundRight = new QPixmap(":/res/images/list_item_context_button_bar_right.png"); + + // --- ANIMATION --- + const int ANIMATION_DURATION_MS = 150; + + m_animation = new QPropertyAnimation(this, "pos", this); + m_animation->setDuration(ANIMATION_DURATION_MS); + + connect(m_animation, SIGNAL(finished()), + this, SLOT(onAnimationFinished())); +} + +ListItemContextButtonBar::~ListItemContextButtonBar() +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_backgroundLeft) + delete m_backgroundLeft; + + if (m_backgroundMiddle) + delete m_backgroundMiddle; + + if (m_backgroundRight) + delete m_backgroundRight; +} + +void ListItemContextButtonBar::changeButtons() +{ + qDebug() << __PRETTY_FUNCTION__; + + Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped); + + if (!isVisible()) + show(); + + // Hide previous buttons (if any) + if (m_contextButtons) + m_contextButtons->setParent(0); + + m_contextButtons = m_newContextButtons; + m_newContextButtons = 0; + m_contextButtons->setParent(this); + m_contextButtons->show(); + setFixedWidth(m_contextButtons->width()); + + // center this widget horizontally to middle of the panel contents area and set outside of + // the view + const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - m_contextButtons->width() / 2; + move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height()); + + // update new target values for animations + m_animation->setStartValue(pos()); + const int Y = 0; + m_animation->setEndValue(QPoint(pos().x(), Y)); +} + +void ListItemContextButtonBar::hideContextButtonBar() +{ + qDebug() << __PRETTY_FUNCTION__; + + m_state = StateClosing; + m_animation->setDirection(QAbstractAnimation::Backward); + m_animation->start(); +} + +void ListItemContextButtonBar::onAnimationFinished() +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_animation->direction() == QAbstractAnimation::Backward) { + m_state = StateHidden; + if (m_newContextButtons) { + changeButtons(); + if (m_waitForOpen) { + m_waitForOpen = false; + showContextButtonBar(); + } + } + } else { + m_state = StateVisible; + } +} + +void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected) +{ + qDebug() << __PRETTY_FUNCTION__; + + if (itemIsSelected) { + if (m_newContextButtons) + m_waitForOpen = true; + else if (m_state != StateVisible) + showContextButtonBar(); + } else { + if (m_newContextButtons) + m_waitForOpen = false; + else if (m_state != StateHidden) + hideContextButtonBar(); + } +} + +void ListItemContextButtonBar::paintEvent(QPaintEvent *event) +{ + qDebug() << __PRETTY_FUNCTION__; + + Q_UNUSED(event); + + QPainter painter(this); + + const int TOP = 0; + const int LEFT = 0; + painter.drawPixmap(TOP, LEFT, *m_backgroundLeft); + painter.drawTiledPixmap(m_backgroundLeft->width(), TOP, + width() - m_backgroundLeft->width() - m_backgroundRight->width(), + height(), + *m_backgroundMiddle); + painter.drawPixmap(width() - m_backgroundRight->width(), TOP, *m_backgroundRight); +} + +void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons) +{ + qDebug() << __PRETTY_FUNCTION__; + + m_newContextButtons = contextButtons; + m_waitForOpen = false; + + if (m_state != StateHidden) + hideContextButtonBar(); + else + changeButtons(); +} + +void ListItemContextButtonBar::showContextButtonBar() +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_contextButtons->layout()->count() > 0) { + m_state = StateOpening; + m_animation->setDirection(QAbstractAnimation::Forward); + m_animation->start(); + } +} diff --git a/src/ui/listitemcontextbuttonbar.h b/src/ui/listitemcontextbuttonbar.h new file mode 100644 index 0000000..71be646 --- /dev/null +++ b/src/ui/listitemcontextbuttonbar.h @@ -0,0 +1,149 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#ifndef LISTITEMCONTEXTBUTTONBAR_H +#define LISTITEMCONTEXTBUTTONBAR_H + +#include + +class QPropertyAnimation; + +/** + * @brief Button bar for list item relatex context buttons + * + * @author Sami Rämö - sami.ramo (at) ixonos.com + */ +class ListItemContextButtonBar : public QWidget +{ + Q_OBJECT +public: + /** + * @brief Constructor + * + * @param parent Parent + */ + explicit ListItemContextButtonBar(QWidget *parent = 0); + + /** + * @brief Destructor + * + * Deletes images. + */ + ~ListItemContextButtonBar(); + +/******************************************************************************* + * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS + ******************************************************************************/ +private: + /** + * @brief Paint the background of the item + * + * @param event Paint event + */ + void paintEvent(QPaintEvent *event); + +/******************************************************************************* + * MEMBER FUNCTIONS AND SLOTS + ******************************************************************************/ +public: + /** + * @brief Start hiding animation + */ + void hideContextButtonBar(); + + /** + * @brief Set new context buttons + * + * If bar is hidden, then changeButtons() is called. Otherwise pointer to new buttons is saved + * and hideContextButtonBar() is called. + * + * @param contextButtons Pointer to new context buttons + */ + void setContextButtons(QWidget *contextButtons); + + /** + * @brief Start showing animation + * + * Animation is started only if the bar contains buttons. + */ + void showContextButtonBar(); + +public slots: + /** + * @brief Shows and hides the bar when item selection is changed + * + * Calls showContextButtonBar() or hideContextButtonBar() if changing the state of the bar is + * required. If there is a pointer to new buttons, then request is remembered instead of + * changing the state immediately. + * + * @param itemIsSelected True is any item is selected + */ + void onListItemSelectionChanged(bool itemIsSelected); + +private: + /** + * @brief Do the actual changing of the buttons + * + * Does also re-sizing and re-positioning of the bar and sets new values for animation. + */ + void changeButtons(); + +private slots: + /** + * @brief + * + * If bar was just hidden, then calls changeButtons() if there is a pointer to new buttons + * saved. If changing the buttons was done, then also checks if showing the bar was requested + * and calls showContextButtonBar() if needed. + */ + void onAnimationFinished(); + +/******************************************************************************* + * DATA MEMBERS + ******************************************************************************/ +private: + /** + * @brief States for the animation + * + * @enum AnimationState + */ + enum AnimationState { + StateHidden, + StateOpening, + StateClosing, + StateVisible + }; + + bool m_waitForOpen; ///< Is showing requested while chaging buttons is not ready + + QPixmap *m_backgroundLeft; ///< Background picture, left part + QPixmap *m_backgroundMiddle; ///< Background picture, center part + QPixmap *m_backgroundRight; ///< Background picture, right part + + QPropertyAnimation *m_animation; ///< Sliding animation for show/hide + + QWidget *m_contextButtons; ///< Widget for context buttons + QWidget *m_newContextButtons; ///< Temporary pointer for new context buttons + + AnimationState m_state; ///< Current state of the animation +}; + +#endif // LISTITEMCONTEXTBUTTONBAR_H diff --git a/src/ui/locationsearchpanel.cpp b/src/ui/locationsearchpanel.cpp index 648a202..63449a0 100644 --- a/src/ui/locationsearchpanel.cpp +++ b/src/ui/locationsearchpanel.cpp @@ -76,7 +76,7 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent) SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&))); connect(m_locationListView, SIGNAL(listItemSelectionChanged()), - this, SLOT(setRouteButtonDisabled())); + this, SLOT(onListItemSelectionChanged())); QVBoxLayout *resultsListViewLayout = new QVBoxLayout; resultsListViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, @@ -97,8 +97,7 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent) panelLayout->addLayout(resultsListViewLayout); // --- CONTEXT BUTTONS --- - m_routeButton = new ImageButton(":res/images/compass.png", "", "", this); - m_routeButton->setDisabled(true); + m_routeButton = new ImageButton(":res/images/routing.png", "", "", this); connect(m_routeButton, SIGNAL(clicked()), this, SLOT(routeToSelectedLocation())); @@ -116,9 +115,9 @@ LocationSearchPanel::LocationSearchPanel(QWidget *parent) connect(m_clearLocationListButton, SIGNAL(clicked()), this, SLOT(showSearchHistoryListView())); - m_contextButtonLayout->addWidget(m_routeButton); - m_contextButtonLayout->addWidget(searchLocationButton); - m_contextButtonLayout->addWidget(m_clearLocationListButton); + m_itemButtonsLayout->addWidget(m_routeButton); + m_genericButtonsLayout->addWidget(searchLocationButton); + m_genericButtonsLayout->addWidget(m_clearLocationListButton); readSettings(); showSearchHistoryListView(); @@ -167,8 +166,6 @@ void LocationSearchPanel::clearListsSelections() m_locationListView->clearItemSelection(); m_searchHistoryListView->clearItemSelection(); - - setRouteButtonDisabled(); } void LocationSearchPanel::hideEvent(QHideEvent *event) @@ -243,13 +240,6 @@ void LocationSearchPanel::setHeaderText(int count) m_resultsLabel->setText(tr("Search results: %1").arg(count)); } -void LocationSearchPanel::setRouteButtonDisabled() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_routeButton->setDisabled(m_locationListView->selectedItems().isEmpty()); -} - void LocationSearchPanel::showLocationListView(int locationItemsCount) { qDebug() << __PRETTY_FUNCTION__; diff --git a/src/ui/locationsearchpanel.h b/src/ui/locationsearchpanel.h index f01890f..e939db7 100644 --- a/src/ui/locationsearchpanel.h +++ b/src/ui/locationsearchpanel.h @@ -132,13 +132,6 @@ private slots: */ void routeToSelectedLocation(); - /** - * @brief Sets route button disabled. - * - * Disabled if there isn't any list item selected. - */ - void setRouteButtonDisabled(); - /******************************************************************************* * SIGNALS ******************************************************************************/ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index e418b85..2ca83a8 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -359,7 +359,7 @@ void MainWindow::buildPanels() buildRoutingPanel(); m_tabbedPanel = new TabbedPanel(this); - + //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out m_situareTabsIndexes.append( m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"))); @@ -398,6 +398,16 @@ void MainWindow::buildPanels() connect(m_tabbedPanel, SIGNAL(currentChanged(int)), m_userInfoPanel, SIGNAL(collapse())); + + // signals for showing and hiding list item context buttons + connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)), + m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool))); + + connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)), + m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool))); + + connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)), + m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool))); } void MainWindow::buildRoutingPanel() diff --git a/src/ui/panelbase.cpp b/src/ui/panelbase.cpp index a0ebc33..72cd122 100644 --- a/src/ui/panelbase.cpp +++ b/src/ui/panelbase.cpp @@ -3,6 +3,7 @@ Copyright (C) 2010 Ixonos Plc. Authors: Pekka Nissinen - pekka.nissinen@ixonos.com + Sami Rämö - sami.ramo@ixonos.com Situare is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,6 +21,8 @@ */ #include +#include +#include #include #include "panelbase.h" @@ -29,27 +32,63 @@ PanelBase::PanelBase(QWidget *parent) { qDebug() << __PRETTY_FUNCTION__; + + // --- GENERIC BUTTONS --- + m_genericButtons = new QWidget; + m_genericButtonsLayout = new QVBoxLayout; + const int CONTEXT_BUTTON_MARGIN_LEFT = 2; const int CONTEXT_BUTTON_MARGIN_TOP = 10; const int CONTEXT_BUTTON_MARGIN_RIGHT = 0; const int CONTEXT_BUTTON_MARGIN_BOTTOM = 0; const int CONTEXT_BUTTON_SPACING = 0; - - m_contextButtons = new QWidget; - - m_contextButtonLayout = new QVBoxLayout; - m_contextButtonLayout->setContentsMargins(CONTEXT_BUTTON_MARGIN_LEFT, + m_genericButtonsLayout->setContentsMargins(CONTEXT_BUTTON_MARGIN_LEFT, CONTEXT_BUTTON_MARGIN_TOP, CONTEXT_BUTTON_MARGIN_RIGHT, CONTEXT_BUTTON_MARGIN_BOTTOM); - m_contextButtonLayout->setSpacing(CONTEXT_BUTTON_SPACING); + m_genericButtonsLayout->setSpacing(CONTEXT_BUTTON_SPACING); + + m_genericButtons->setLayout(m_genericButtonsLayout); + + // --- ITEM RELATED BUTTONS --- + m_itemButtons = new QWidget(this); + m_itemButtonsLayout = new QHBoxLayout; + + const int ITEM_CONTEXT_BUTTON_MARGIN_BOTTOM = 0; + const int ITEM_CONTEXT_BUTTON_MARGIN_LEFT = 2; + const int ITEM_CONTEXT_BUTTON_MARGIN_RIGHT = 2; + const int ITEM_CONTEXT_BUTTON_MARGIN_TOP = 2; + const int ITEM_CONTEXT_BUTTON_SPACING = 0; + m_itemButtonsLayout->setContentsMargins(ITEM_CONTEXT_BUTTON_MARGIN_LEFT, + ITEM_CONTEXT_BUTTON_MARGIN_TOP, + ITEM_CONTEXT_BUTTON_MARGIN_RIGHT, + ITEM_CONTEXT_BUTTON_MARGIN_BOTTOM); + m_itemButtonsLayout->setSpacing(ITEM_CONTEXT_BUTTON_SPACING); + + m_itemButtons->setLayout(m_itemButtonsLayout); +} + +QWidget* PanelBase::genericPanelButtons() const +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_genericButtons; +} + +QWidget* PanelBase::itemButtons() const +{ + qDebug() << __PRETTY_FUNCTION__; - m_contextButtons->setLayout(m_contextButtonLayout); + return m_itemButtons; } -QWidget* PanelBase::contextButtons() const +void PanelBase::onListItemSelectionChanged() { qDebug() << __PRETTY_FUNCTION__; - return m_contextButtons; + QListWidget *listWidget = dynamic_cast(sender()); + if (listWidget && (listWidget->selectedItems().count() > 0)) + emit listItemSelectionChanged(true); + else + emit listItemSelectionChanged(false); } diff --git a/src/ui/panelbase.h b/src/ui/panelbase.h index 6f4dd0a..dee16ab 100644 --- a/src/ui/panelbase.h +++ b/src/ui/panelbase.h @@ -3,6 +3,7 @@ Copyright (C) 2010 Ixonos Plc. Authors: Pekka Nissinen - pekka.nissinen@ixonos.com + Sami Rämö - sami.ramo@ixonos.com Situare is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -24,6 +25,8 @@ #include +class QHBoxLayout; +class QListWidgetItem; class QVBoxLayout; class ImageButton; @@ -32,6 +35,7 @@ class ImageButton; * @brief Base class for panels * * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com + * @author Sami Rämö - sami.ramo (at) ixonos.com */ class PanelBase : public QWidget { @@ -50,11 +54,26 @@ public: ******************************************************************************/ public: /** - * @brief Getter for the context buttons + * @brief Getter for the generic panel related context buttons * * @returns Pointer to context buttons widget */ - QWidget* contextButtons() const; + QWidget* genericPanelButtons() const; + + /** + * @brief Getter for the list item related context buttons + * + * @returns Pointer to context buttons widget + */ + QWidget* itemButtons() const; + +protected slots: + /** + * @brief Call when there is a change in list item selection + * + * Emits listItemSelectionChanged(bool). Parameter is true if any item is selected. + */ + void onListItemSelectionChanged(); /******************************************************************************* * SIGNALS @@ -67,13 +86,22 @@ signals: */ void openPanelRequested(QWidget *widget); + /** + * @brief Emitted when there is a change in list item selection + * + * @param itemIsSelected True if any item is selected. + */ + void listItemSelectionChanged(bool itemIsSelected); + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ protected: - QVBoxLayout *m_contextButtonLayout; ///< Layout for context buttons + QVBoxLayout *m_genericButtonsLayout; ///< Layout for generic context buttons + QHBoxLayout *m_itemButtonsLayout; ///< Layout for item related context buttons private: - QWidget *m_contextButtons; ///< Widget for context buttons + QWidget *m_genericButtons; ///< Widget for generic context buttons + QWidget *m_itemButtons; ///< Widget for item related context buttons }; #endif // PANELBASE_H diff --git a/src/ui/panelcommon.h b/src/ui/panelcommon.h index d721628..c3fcd64 100644 --- a/src/ui/panelcommon.h +++ b/src/ui/panelcommon.h @@ -41,7 +41,7 @@ const int PANEL_BOTTOM_PADDING = 0; ///< Amount of padding in bottom of panels const int PANEL_BAR_WIDTH = 5; ///< Width of the slider bar const int PANEL_TAB_BAR_WIDTH = 74; ///< Panel tab bar total width const int PANEL_BAR_TABBED_WIDTH = PANEL_BAR_WIDTH + PANEL_TAB_BAR_WIDTH; ///< Width of the tabbed bar -const int PANEL_WIDTH = 384; ///< Width of the panel +const int PANEL_WIDTH = 384; ///< Width of the panel contents area const int PANEL_HEIGHT = DEFAULT_SCREEN_HEIGHT - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING; ///< Height of the panel diff --git a/src/ui/routingpanel.cpp b/src/ui/routingpanel.cpp index 45998f4..55b711f 100644 --- a/src/ui/routingpanel.cpp +++ b/src/ui/routingpanel.cpp @@ -43,6 +43,9 @@ RoutingPanel::RoutingPanel(QWidget *parent) connect(m_routeWaypointListView, SIGNAL(routeWaypointItemClicked(GeoCoordinate)), this, SIGNAL(routeWaypointItemClicked(GeoCoordinate))); + connect(m_routeWaypointListView, SIGNAL(listItemSelectionChanged()), + this, SLOT(onListItemSelectionChanged())); + QVBoxLayout *panelLayout = new QVBoxLayout; panelLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP, PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM); @@ -62,8 +65,8 @@ RoutingPanel::RoutingPanel(QWidget *parent) this, SLOT(clearRouteButtonClicked())); m_clearRouteButton->setDisabled(true); - m_contextButtonLayout->addWidget(routeToCursorButton); - m_contextButtonLayout->addWidget(m_clearRouteButton); + m_genericButtonsLayout->addWidget(routeToCursorButton); + m_genericButtonsLayout->addWidget(m_clearRouteButton); } void RoutingPanel::clearListsSelections() diff --git a/src/ui/tabbedpanel.cpp b/src/ui/tabbedpanel.cpp index af58c61..3f130fc 100644 --- a/src/ui/tabbedpanel.cpp +++ b/src/ui/tabbedpanel.cpp @@ -29,6 +29,7 @@ #include #include +#include "listitemcontextbuttonbar.h" #include "panelbar.h" #include "panelbase.h" #include "panelcontentstack.h" @@ -73,7 +74,7 @@ TabbedPanel::TabbedPanel(QWidget *parent) m_panelBar = new PanelBar(this); m_panelBar->move(PANEL_TAB_BAR_WIDTH, PANEL_TOP_Y); - // --- CONTEXT BUTTON BAR --- + // --- GENERIC PANEL CONTEXT BUTTON BAR --- m_panelContextButtonBar = new PanelContextButtonBar(this); m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, PANEL_HEIGHT); @@ -83,9 +84,17 @@ TabbedPanel::TabbedPanel(QWidget *parent) connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()), this, SLOT(repositionContextButtonBar())); + // --- LIST ITEM RELATED CONTEXT BUTTONS BAR --- + m_itemContextButtonBar = new ListItemContextButtonBar(this); + m_itemContextButtonBar->hide(); + + connect(this, SIGNAL(listItemSelectionChanged(bool)), + m_itemContextButtonBar, SLOT(onListItemSelectionChanged(bool))); + // --- PANEL CONTENT --- m_panelContentStack = new PanelContentStack(this); m_panelContentStack->move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y); + m_panelContentStack->stackUnder(m_itemContextButtonBar); // --- PANEL ANIMATION --- QStateMachine *panelStateMachine = new QStateMachine(this); @@ -209,7 +218,7 @@ void TabbedPanel::repositionContextButtonBar() qDebug() << __PRETTY_FUNCTION__; m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height()); - + calculateMask(); } @@ -252,7 +261,10 @@ void TabbedPanel::setCurrentIndex(int index) openPanel(); m_panelContextButtonBar->setContextButtons( - static_cast(m_panelContentStack->widget(index))->contextButtons()); + static_cast(m_panelContentStack->widget(index))->genericPanelButtons()); + + QWidget *itemContextButtons = static_cast(m_panelContentStack->widget(index))->itemButtons(); + m_itemContextButtonBar->setContextButtons(itemContextButtons); emit currentChanged(index); } diff --git a/src/ui/tabbedpanel.h b/src/ui/tabbedpanel.h index 12fefa9..87a056d 100644 --- a/src/ui/tabbedpanel.h +++ b/src/ui/tabbedpanel.h @@ -32,6 +32,7 @@ class QSignalTransition; class QState; class QStateMachine; +class ListItemContextButtonBar; class PanelBar; class PanelContentStack; class PanelContextButtonBar; @@ -163,6 +164,13 @@ signals: void currentChanged(int index); /** + * @brief Emitted when there is a change in list item selection + * + * @param itemIsSelected True if any item is selected. + */ + void listItemSelectionChanged(bool itemIsSelected); + + /** * @brief Signal that is sent when panel is closed * * @sa openPanel @@ -196,6 +204,7 @@ private: QState *m_stateClosed; ///< State of the closed panel QState *m_stateOpened; ///< State of the opened panel + ListItemContextButtonBar *m_itemContextButtonBar; ///< Widget for list item context button bar PanelBar *m_panelBar; ///< Widget for panel bar PanelContentStack *m_panelContentStack; ///< Stack for panel widgets PanelContextButtonBar * m_panelContextButtonBar; ///< Widget for panel context button bar diff --git a/src/ui/userinfopanel.cpp b/src/ui/userinfopanel.cpp index 2c48092..c71defc 100644 --- a/src/ui/userinfopanel.cpp +++ b/src/ui/userinfopanel.cpp @@ -89,8 +89,8 @@ UserInfoPanel::UserInfoPanel(QWidget *parent) ":/res/images/send_position_s.png", "", this); - m_contextButtonLayout->addWidget(updateFriendsButton); - m_contextButtonLayout->addWidget(updateStatusMessageButton); + m_genericButtonsLayout->addWidget(updateFriendsButton); + m_genericButtonsLayout->addWidget(updateStatusMessageButton); connect(updateFriendsButton, SIGNAL(clicked()), this, SIGNAL(refreshUserData())); diff --git a/tests/ui/tabbedpanel/tabbedpanel.pro b/tests/ui/tabbedpanel/tabbedpanel.pro index 1b298f8..ba0807d 100644 --- a/tests/ui/tabbedpanel/tabbedpanel.pro +++ b/tests/ui/tabbedpanel/tabbedpanel.pro @@ -9,7 +9,8 @@ SOURCES += \ ../../../src/ui/panelcontentstack.cpp \ ../../../src/ui/panelcontextbuttonbar.cpp \ ../../../src/ui/paneltab.cpp \ - ../../../src/ui/paneltabbar.cpp + ../../../src/ui/paneltabbar.cpp \ + ../../../src/ui/listitemcontextbuttonbar.cpp HEADERS += \ ../../../src/ui/tabbedpanel.h \ ../../../src/ui/panelbar.h \ @@ -18,6 +19,7 @@ HEADERS += \ ../../../src/ui/panelcontextbuttonbar.h \ ../../../src/ui/paneltab.h \ ../../../src/ui/paneltabbar.h \ - ../../../src/ui/panelcommon.h + ../../../src/ui/panelcommon.h \ + ../../../src/ui/listitemcontextbuttonbar.h RESOURCES += ../../../images.qrc DEFINES += QT_NO_DEBUG_OUTPUT