~ubuntu-branches/ubuntu/precise/tetzle/precise

« back to all changes in this revision

Viewing changes to src/toolbar_list.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2011-06-02 02:51:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110602025109-6jmxy9wekpwlrkw6
Tags: 2.0.0-1
* Synced with https://launchpad.net/~gottcode/+archive/gcppa/
* debian/control: Fixed "dpkg-source: warning: unknown information field
  'Suggests' in input data in general section of control info file".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
 *
 
3
 * Copyright (C) 2011 Graeme Gott <graeme@gottcode.org>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 ***********************************************************************/
 
19
 
 
20
#include "toolbar_list.h"
 
21
 
 
22
#include <QToolBar>
 
23
 
 
24
//-----------------------------------------------------------------------------
 
25
 
 
26
ToolBarList::ToolBarList(QWidget* parent)
 
27
        : QListWidget(parent)
 
28
{
 
29
        m_toolbar = new QToolBar(this);
 
30
        m_toolbar->setFloatable(false);
 
31
        m_toolbar->setMovable(false);
 
32
        m_toolbar->setIconSize(QSize(16,16));
 
33
        m_toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
 
34
        m_toolbar->setStyleSheet("QToolBar { border-top: 1px solid palette(mid); }");
 
35
        m_toolbar->hide();
 
36
 
 
37
        setContextMenuPolicy(Qt::ActionsContextMenu);
 
38
        setMovement(QListView::Static);
 
39
        setResizeMode(QListView::Adjust);
 
40
        setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
 
41
}
 
42
 
 
43
//-----------------------------------------------------------------------------
 
44
 
 
45
void ToolBarList::addToolBarAction(QAction* action)
 
46
{
 
47
        if (action) {
 
48
                addAction(action);
 
49
                m_toolbar->addAction(action);
 
50
                m_toolbar->show();
 
51
                updateGeometries();
 
52
        }
 
53
}
 
54
 
 
55
//-----------------------------------------------------------------------------
 
56
 
 
57
void ToolBarList::updateGeometries()
 
58
{
 
59
        // Resize viewport margins
 
60
        QSize hint = m_toolbar->isHidden() ? QSize(0,0) : m_toolbar->sizeHint();
 
61
        setViewportMargins(0, 0, 0, hint.height());
 
62
 
 
63
        // Resize toolbar
 
64
        QRect rect = viewport()->geometry();
 
65
        QRect geometry(rect.left(), rect.top() + rect.height(), rect.width(), hint.height());
 
66
        m_toolbar->setGeometry(geometry);
 
67
 
 
68
        QListWidget::updateGeometries();
 
69
}
 
70
 
 
71
//-----------------------------------------------------------------------------