Added mask calculation to panel.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 31 Aug 2010 07:06:20 +0000 (10:06 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 31 Aug 2010 07:06:20 +0000 (10:06 +0300)
src/ui/listview.h
src/ui/panelbar.cpp
src/ui/panelcommon.h
src/ui/panelcontextbuttonbar.cpp
src/ui/paneltab.cpp
src/ui/paneltabbar.cpp
src/ui/paneltabbar.h
src/ui/tabbedpanel.cpp
src/ui/tabbedpanel.h

index 6da9b6b..417c5d1 100644 (file)
@@ -186,7 +186,13 @@ private slots:
     */
     void listItemClicked(QListWidgetItem *item);
 
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
 signals:
+    /**
+    * @brief Emitted when list item selection changes.
+    */
     void listItemSelectionChanged();
 
 /*******************************************************************************
index 697d22e..9282f21 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <QDebug>
 #include <QPainter>
-#include <QRegion>
 
 #include "panelbar.h"
 
index ccafaa3..251ee53 100644 (file)
@@ -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
index be6e9d0..c39f374 100644 (file)
@@ -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)
index db1101f..95276ad 100644 (file)
@@ -24,9 +24,9 @@
 #include <QPainter>
 #include <QRect>
 
+#include "panelcommon.h"
 #include "paneltab.h"
 
-const int TAB_WIDTH_ACTIVE = 74;
 const int TAB_HEIGHT = 66;
 
 PanelTab::PanelTab(QWidget *parent)
index 8f394dd..123d0ec 100644 (file)
 #include <QDebug>
 #include <QButtonGroup>
 
+#include "panelcommon.h"
 #include "paneltab.h"
 
 #include "paneltabbar.h"
 
-// REMOVE WHEN NOT NEEDED ANYMORE
-#include <QPainter>
-
 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<QAbstractButton *> 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();
 }
index 439ae07..be4c3c1 100644 (file)
@@ -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
index 49dd1b6..d5deee7 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QDebug>
 #include <QPropertyAnimation>
+#include <QRegion>
 #include <QSignalTransition>
 #include <QStackedWidget>
 #include <QStateMachine>
@@ -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();
index 5420bf0..6a483bf 100644 (file)
@@ -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();