From 57e073684d7ecd84432cb97464ada8414de40187 Mon Sep 17 00:00:00 2001 From: Jussi Laitinen Date: Tue, 31 Aug 2010 10:06:20 +0300 Subject: [PATCH] Added mask calculation to panel. --- src/ui/listview.h | 6 ++++++ src/ui/panelbar.cpp | 1 - src/ui/panelcommon.h | 2 ++ src/ui/panelcontextbuttonbar.cpp | 6 ------ src/ui/paneltab.cpp | 2 +- src/ui/paneltabbar.cpp | 25 +++++++------------------ src/ui/paneltabbar.h | 12 +++++------- src/ui/tabbedpanel.cpp | 34 +++++++++++++++++++++++++++++++++- src/ui/tabbedpanel.h | 7 +++++++ 9 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/ui/listview.h b/src/ui/listview.h index 6da9b6b..417c5d1 100644 --- a/src/ui/listview.h +++ b/src/ui/listview.h @@ -186,7 +186,13 @@ private slots: */ void listItemClicked(QListWidgetItem *item); +/****************************************************************************** +* SIGNALS +******************************************************************************/ signals: + /** + * @brief Emitted when list item selection changes. + */ void listItemSelectionChanged(); /******************************************************************************* diff --git a/src/ui/panelbar.cpp b/src/ui/panelbar.cpp index 697d22e..9282f21 100644 --- a/src/ui/panelbar.cpp +++ b/src/ui/panelbar.cpp @@ -22,7 +22,6 @@ #include #include -#include #include "panelbar.h" diff --git a/src/ui/panelcommon.h b/src/ui/panelcommon.h index ccafaa3..251ee53 100644 --- a/src/ui/panelcommon.h +++ b/src/ui/panelcommon.h @@ -56,6 +56,8 @@ const int PANEL_CLOSED_X = DEFAULT_SCREEN_WIDTH - PANEL_TAB_WIDTH const int PANEL_OPENED_X = DEFAULT_SCREEN_WIDTH - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH; ///< Horizontal position of a open panel +const int TAB_WIDTH_ACTIVE = 74; ///< Active tab's width + // Zoom button panel settings const int ZOOM_BUTTON_PANEL_POSITION_X = 10; ///< Horizontal position of zoom panel const int ZOOM_BUTTON_PANEL_POSITION_Y = 10; ///< Vertical position of zoom panel diff --git a/src/ui/panelcontextbuttonbar.cpp b/src/ui/panelcontextbuttonbar.cpp index be6e9d0..c39f374 100644 --- a/src/ui/panelcontextbuttonbar.cpp +++ b/src/ui/panelcontextbuttonbar.cpp @@ -134,12 +134,6 @@ void PanelContextButtonBar::paintEvent(QPaintEvent *event) painter.drawPixmap(CONTEXT_BUTTON_BAR_TOP_X, CONTEXT_BUTTON_BAR_TOP_Y, m_barTop); painter.drawTiledPixmap(m_barRect, m_barTile); - - // Temporary border, REMOVE WHEN NOT NEEDED ANYMORE! - painter.setPen(Qt::red); - painter.drawRect(this->rect().x(), this->rect().y(), - this->rect().width() - 1, this->rect().height() - 1); - } void PanelContextButtonBar::setContextButtons(QWidget *contextButtons) diff --git a/src/ui/paneltab.cpp b/src/ui/paneltab.cpp index db1101f..95276ad 100644 --- a/src/ui/paneltab.cpp +++ b/src/ui/paneltab.cpp @@ -24,9 +24,9 @@ #include #include +#include "panelcommon.h" #include "paneltab.h" -const int TAB_WIDTH_ACTIVE = 74; const int TAB_HEIGHT = 66; PanelTab::PanelTab(QWidget *parent) diff --git a/src/ui/paneltabbar.cpp b/src/ui/paneltabbar.cpp index 8f394dd..123d0ec 100644 --- a/src/ui/paneltabbar.cpp +++ b/src/ui/paneltabbar.cpp @@ -22,13 +22,11 @@ #include #include +#include "panelcommon.h" #include "paneltab.h" #include "paneltabbar.h" -// REMOVE WHEN NOT NEEDED ANYMORE -#include - const int APPEND_INDEX = -1; const int NO_ACTIVE_TABS = -1; @@ -78,20 +76,6 @@ int PanelTabBar::insertTab(int index, const QIcon& icon) return index; } -// Used to draw temporary border around widget, REMOVE WHEN NOT NEEDED ANYMORE! -void PanelTabBar::paintEvent(QPaintEvent *event) -{ - qDebug() << __PRETTY_FUNCTION__; - - Q_UNUSED(event); - - QPainter painter(this); - - painter.setPen(Qt::red); - painter.drawRect(this->rect().x(), this->rect().y(), - this->rect().width() - 1, this->rect().height() - 1); -} - void PanelTabBar::removeTab(int index) { qDebug() << __PRETTY_FUNCTION__; @@ -132,8 +116,13 @@ void PanelTabBar::setUpTabLayout() const int TAB_BUTTON_STEPPING = 65; QList tabList = m_tabButtonGroup->buttons(); - + int tabListHeight = 0; for (int i = 0; i < tabList.size(); i ++) { tabList.at(i)->move(0, i * TAB_BUTTON_STEPPING); + tabListHeight += TAB_BUTTON_STEPPING; } + + resize(TAB_WIDTH_ACTIVE, tabListHeight); + + emit sizeChangeRequested(); } diff --git a/src/ui/paneltabbar.h b/src/ui/paneltabbar.h index 439ae07..be4c3c1 100644 --- a/src/ui/paneltabbar.h +++ b/src/ui/paneltabbar.h @@ -44,13 +44,6 @@ public: PanelTabBar(QWidget *parent = 0); /******************************************************************************* - * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS - ******************************************************************************/ -protected: - // Used to draw temporary border around widget, REMOVE WHEN NOT NEEDED ANYMORE! - void paintEvent(QPaintEvent *event); - -/******************************************************************************* * MEMBER FUNCTIONS AND SLOTS ******************************************************************************/ public: @@ -124,6 +117,11 @@ signals: void currentChanged(int index); /** + * @brief This signal is emitted whenever content is changed. + */ + void sizeChangeRequested(); + + /** * @brief This signal is emitted whenever user wants to close a tab * * @param index Index of the currently active tab diff --git a/src/ui/tabbedpanel.cpp b/src/ui/tabbedpanel.cpp index 49dd1b6..d5deee7 100644 --- a/src/ui/tabbedpanel.cpp +++ b/src/ui/tabbedpanel.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include "tabbedpanel.h" const int PANEL_CONTEXT_BUTTON_BAR_LEFT_X = 1; +const int PANEL_TAB_BAR_TOP_SPACING = 8; TabbedPanel::TabbedPanel(QWidget *parent) : QWidget(parent), @@ -45,7 +47,6 @@ TabbedPanel::TabbedPanel(QWidget *parent) const int PANEL_LEFT_X = 0; const int PANEL_TOP_Y = 0; - const int PANEL_TAB_BAR_TOP_SPACING = 8; resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT); move(PANEL_CLOSED_X, PANEL_TOP_PADDING); @@ -63,6 +64,9 @@ TabbedPanel::TabbedPanel(QWidget *parent) connect(this, SIGNAL(panelClosed()), m_panelTabBar, SLOT(deselectTabs())); + connect(m_panelTabBar, SIGNAL(sizeChangeRequested()), + this, SLOT(calculateMask())); + // --- BAR --- m_panelBar = new PanelBar(this); m_panelBar->move(PANEL_TAB_WIDTH, PANEL_TOP_Y); @@ -122,6 +126,29 @@ int TabbedPanel::addTab(QWidget *widget, const QIcon& icon) return insertTab(APPEND_INDEX, widget, icon); } +void TabbedPanel::calculateMask() +{ + qDebug() << __PRETTY_FUNCTION__; + + QRect panelTabBarRect = m_panelTabBar->rect(); + QRect panelContextButtonBarRect = m_panelContextButtonBar->rect(); + int panelContextButtonBarY = height() - panelContextButtonBarRect.height(); + + if (!m_open) + panelContextButtonBarY = height(); + + QRegion panelTabBarRegion(0, PANEL_TAB_BAR_TOP_SPACING, + panelTabBarRect.width(), panelTabBarRect.height()); + QRegion panelContextButtonBarRegion(0, panelContextButtonBarY, + panelContextButtonBarRect.width(), + panelContextButtonBarRect.height()); + QRegion panelContentRegion(panelTabBarRect.right() + 1, 0, + PANEL_WIDTH, height()); + QRegion panelRegion = panelTabBarRegion + panelContentRegion + panelContextButtonBarRegion; + + setMask(panelRegion); +} + void TabbedPanel::closePanel() { qDebug() << __PRETTY_FUNCTION__; @@ -180,6 +207,7 @@ void TabbedPanel::repositionContextButtonBar() qDebug() << __PRETTY_FUNCTION__; m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height()); + calculateMask(); } void TabbedPanel::resizePanel(const QSize &size) @@ -206,6 +234,8 @@ void TabbedPanel::resizePanel(const QSize &size) QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING); m_stateOpened->assignProperty(this, "pos", openedPosition); + + calculateMask(); } void TabbedPanel::setCurrentIndex(int index) @@ -229,6 +259,8 @@ void TabbedPanel::stateChanged() { qDebug() << __PRETTY_FUNCTION__; + calculateMask(); + if (m_open) { m_panelContextButtonBar->showContextButtonBar(); emit panelOpened(); diff --git a/src/ui/tabbedpanel.h b/src/ui/tabbedpanel.h index 5420bf0..6a483bf 100644 --- a/src/ui/tabbedpanel.h +++ b/src/ui/tabbedpanel.h @@ -119,6 +119,13 @@ public slots: private slots: /** + * @brief Calculates mask for this widget. + * + * Mask is constructed from PanelTabBar, PanelContextButtonBar and panel content sizes. + */ + void calculateMask(); + + /** * @brief Repositions context button bar */ void repositionContextButtonBar(); -- 1.7.9.5