Workaround Qt 5.4 issue: Re-add a config file to the file watcher if it's already...
[lxde/liblxqt.git] / configdialog / lxqtpageselectwidget.cpp
CommitLineData
4ef6cee9 1/* BEGIN_COMMON_COPYRIGHT_HEADER
c4af778e 2 * (c)LGPL2+
4ef6cee9 3 *
b9223fe7 4 * LXQt - a lightweight, Qt based, desktop toolset
4ef6cee9 5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
626f1f31 9 * Alexander Sokoloff <sokoloff.a@gmail.com>
4ef6cee9 10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
c4af778e 14 * version 2.1 of the License, or (at your option) any later version.
4ef6cee9 15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28
b6483430 29#include "lxqtpageselectwidget.h"
e6389bfc 30#include <QDebug>
afd3b116 31#include <QStyledItemDelegate>
154a38ff 32#include <QScrollBar>
4ef6cee9 33
ad7ee7e8
AS
34using namespace LxQt;
35
4ef6cee9 36class PageSelectWidgetItemDelegate: public QStyledItemDelegate
37{
38public:
39 explicit PageSelectWidgetItemDelegate(PageSelectWidget *parent = 0);
40 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
41
42private:
43 PageSelectWidget* mView;
44};
45
46
47/************************************************
48
49 ************************************************/
50PageSelectWidgetItemDelegate::PageSelectWidgetItemDelegate(PageSelectWidget *parent):
51 QStyledItemDelegate(parent),
52 mView(parent)
53{
54}
55
56
57/************************************************
58
59 ************************************************/
60QSize PageSelectWidgetItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
61{
62 QSize size = QStyledItemDelegate::sizeHint(option, index);
ca9b082d 63 size.setWidth(mView->viewport()->width() - 2*mView->spacing());
4ef6cee9 64 return size;
65}
66
67
68
69/************************************************
70
71 ************************************************/
72PageSelectWidget::PageSelectWidget(QWidget *parent) :
73 QListWidget(parent)
74{
75 setSelectionRectVisible(false);
76 setViewMode(IconMode);
77 setSpacing(2);
ca9b082d 78 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
4ef6cee9 79 setWordWrap(true);
80 setDragEnabled(NoDragDrop);
81 setEditTriggers(NoEditTriggers);
82 setTextElideMode(Qt::ElideNone);
83
84 setItemDelegate(new PageSelectWidgetItemDelegate(this));
85}
86
87
88/************************************************
89
90 ************************************************/
91PageSelectWidget::~PageSelectWidget()
92{
93}
94
95
96/************************************************
97
98 ************************************************/
99QSize PageSelectWidget::sizeHint() const
100{
101 QSize size = QListWidget::sizeHint();
102 int w = 0;
103 for(int i=0; i< count(); ++i)
104 {
105 QRect rect = fontMetrics().boundingRect(QRect(), Qt::AlignLeft | Qt::TextWordWrap, item(i)->text());
106 w = qMax(w, rect.width());
107 }
108
109 if (horizontalScrollBar()->isVisible())
110 w += horizontalScrollBar()->width();
ca9b082d 111 size.setWidth(w + frameWidth() + spacing()*2 + 10);
4ef6cee9 112 return size;
113}