Tuning the ListItemContextButtonBar look
[situare] / src / ui / panelbase.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Pekka Nissinen - pekka.nissinen@ixonos.com
6         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include <QDebug>
24 #include <QListWidget>
25 #include <QResizeEvent>
26 #include <QVBoxLayout>
27
28 #include "panelbase.h"
29
30 PanelBase::PanelBase(QWidget *parent)
31     : QWidget(parent)
32 {
33     qDebug() << __PRETTY_FUNCTION__;
34
35
36     // --- GENERIC BUTTONS ---
37     m_genericButtons = new QWidget;
38     m_genericButtonsLayout = new QVBoxLayout;
39
40     const int CONTEXT_BUTTON_MARGIN_LEFT = 2;
41     const int CONTEXT_BUTTON_MARGIN_TOP = 10;
42     const int CONTEXT_BUTTON_MARGIN_RIGHT = 0;
43     const int CONTEXT_BUTTON_MARGIN_BOTTOM = 0;
44     const int CONTEXT_BUTTON_SPACING = 0;
45     m_genericButtonsLayout->setContentsMargins(CONTEXT_BUTTON_MARGIN_LEFT,
46                                               CONTEXT_BUTTON_MARGIN_TOP,
47                                               CONTEXT_BUTTON_MARGIN_RIGHT,
48                                               CONTEXT_BUTTON_MARGIN_BOTTOM);
49     m_genericButtonsLayout->setSpacing(CONTEXT_BUTTON_SPACING);
50
51     m_genericButtons->setLayout(m_genericButtonsLayout);
52
53     // --- ITEM RELATED BUTTONS ---
54     m_itemButtons = new QWidget(this);
55     m_itemButtonsLayout = new QHBoxLayout;
56
57     const int ITEM_CONTEXT_BUTTON_MARGIN_BOTTOM = 0;
58     const int ITEM_CONTEXT_BUTTON_MARGIN_LEFT = 2;
59     const int ITEM_CONTEXT_BUTTON_MARGIN_RIGHT = 2;
60     const int ITEM_CONTEXT_BUTTON_MARGIN_TOP = 2;
61     const int ITEM_CONTEXT_BUTTON_SPACING = 0;
62     m_itemButtonsLayout->setContentsMargins(ITEM_CONTEXT_BUTTON_MARGIN_LEFT,
63                                             ITEM_CONTEXT_BUTTON_MARGIN_TOP,
64                                             ITEM_CONTEXT_BUTTON_MARGIN_RIGHT,
65                                             ITEM_CONTEXT_BUTTON_MARGIN_BOTTOM);
66     m_itemButtonsLayout->setSpacing(ITEM_CONTEXT_BUTTON_SPACING);
67
68     m_itemButtons->setLayout(m_itemButtonsLayout);
69 }
70
71 QWidget* PanelBase::genericPanelButtons() const
72 {
73     qDebug() << __PRETTY_FUNCTION__;
74
75     return m_genericButtons;
76 }
77
78 QWidget* PanelBase::itemButtons() const
79 {
80     qDebug() << __PRETTY_FUNCTION__;
81
82     return m_itemButtons;
83 }
84
85 void PanelBase::onListItemSelectionChanged()
86 {
87     qDebug() << __PRETTY_FUNCTION__;
88
89     QListWidget *listWidget = dynamic_cast<QListWidget *>(sender());
90     if (listWidget && (listWidget->selectedItems().count() > 0))
91         emit listItemSelectionChanged(true);
92     else
93         emit listItemSelectionChanged(false);
94 }