File indexing completed on 2024-04-28 05:08:26
0001 /*************************************************************************** 0002 Copyright (C) 2002-2011 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "viewstack.h" 0026 #include "detailedlistview.h" 0027 #include "entryiconview.h" 0028 #include "config/tellico_config.h" 0029 0030 #include <KLocalizedString> 0031 0032 #include <QIcon> 0033 #include <QHBoxLayout> 0034 #include <QVBoxLayout> 0035 #include <QToolButton> 0036 #include <QStackedWidget> 0037 #include <QSlider> 0038 #include <QButtonGroup> 0039 0040 namespace { 0041 static const int MIN_ENTRY_ICON_SIZE = 64; 0042 static const int MAX_ENTRY_ICON_SIZE = 512; 0043 static const int SMALL_INCREMENT_ICON_SIZE = 1; 0044 static const int LARGE_INCREMENT_ICON_SIZE = 8; 0045 } 0046 0047 using Tellico::ViewStack; 0048 0049 ViewStack::ViewStack(QWidget* parent_) : QWidget(parent_) 0050 , m_listView(new DetailedListView(this)) 0051 , m_iconView(new EntryIconView(this)) { 0052 QBoxLayout* lay = new QVBoxLayout(); 0053 lay->setMargin(0); 0054 lay->setSpacing(0); 0055 0056 QBoxLayout* hlay = new QHBoxLayout(); 0057 lay->addLayout(hlay); 0058 hlay->setMargin(0); 0059 hlay->setSpacing(0); 0060 0061 m_listButton = new QToolButton(this); 0062 m_listButton->setCheckable(true); 0063 m_listButton->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); 0064 connect(m_listButton, &QAbstractButton::clicked, this, &ViewStack::showListView); 0065 0066 m_iconButton = new QToolButton(this); 0067 m_iconButton->setCheckable(true); 0068 m_iconButton->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); 0069 connect(m_iconButton, &QAbstractButton::clicked, this, &ViewStack::showIconView); 0070 0071 QButtonGroup* bg = new QButtonGroup(this); 0072 bg->addButton(m_listButton); 0073 bg->addButton(m_iconButton); 0074 0075 hlay->addWidget(m_listButton); 0076 hlay->addWidget(m_iconButton); 0077 hlay->addStretch(10); 0078 0079 m_decreaseIconSizeButton = new QToolButton(this); 0080 m_decreaseIconSizeButton->setIcon(QIcon::fromTheme(QStringLiteral("zoom-out"))); 0081 m_decreaseIconSizeButton->setToolTip(i18n("Decrease the maximum icon size in the icon list view")); 0082 hlay->addWidget(m_decreaseIconSizeButton); 0083 connect(m_decreaseIconSizeButton, &QAbstractButton::clicked, this, &ViewStack::slotDecreaseIconSizeButtonClicked); 0084 0085 m_iconSizeSlider = new QSlider(Qt::Horizontal, this); 0086 m_iconSizeSlider->setMinimum(MIN_ENTRY_ICON_SIZE); 0087 m_iconSizeSlider->setMaximum(MAX_ENTRY_ICON_SIZE); 0088 m_iconSizeSlider->setSingleStep(SMALL_INCREMENT_ICON_SIZE); 0089 m_iconSizeSlider->setPageStep(LARGE_INCREMENT_ICON_SIZE); 0090 m_iconSizeSlider->setValue(Config::maxIconSize()); 0091 m_iconSizeSlider->setTracking(true); 0092 m_iconSizeSlider->setToolTip(i18n("The current maximum icon size is %1.\nMove the slider to change it.", Config::maxIconSize())); 0093 hlay->addWidget(m_iconSizeSlider); 0094 connect(m_iconSizeSlider, &QAbstractSlider::valueChanged, this, &ViewStack::slotIconSizeSliderChanged); 0095 0096 m_increaseIconSizeButton = new QToolButton(this); 0097 m_increaseIconSizeButton->setIcon(QIcon::fromTheme(QStringLiteral("zoom-in"))); 0098 m_increaseIconSizeButton->setToolTip(i18n("Increase the maximum icon size in the icon list view")); 0099 hlay->addWidget(m_increaseIconSizeButton, 0); 0100 connect(m_increaseIconSizeButton, &QAbstractButton::clicked, this, &ViewStack::slotIncreaseIconSizeButtonClicked); 0101 0102 setIconSizeInterfaceVisible(false); 0103 0104 m_stack = new QStackedWidget(this); 0105 lay->addWidget(m_stack); 0106 m_stack->addWidget(m_listView); 0107 m_stack->addWidget(m_iconView); 0108 0109 setLayout(lay); 0110 } 0111 0112 int ViewStack::currentWidget() const { 0113 if(m_stack->currentWidget() == m_listView) { 0114 return Config::ListView; 0115 } else { 0116 return Config::IconView; 0117 } 0118 } 0119 0120 void ViewStack::setCurrentWidget(int widget_) { 0121 switch(widget_) { 0122 case Config::ListView: 0123 m_listButton->setChecked(true); 0124 showListView(); 0125 break; 0126 case Config::IconView: 0127 m_iconButton->setChecked(true); 0128 showIconView(); 0129 break; 0130 } 0131 } 0132 0133 void ViewStack::showListView() { 0134 setIconSizeInterfaceVisible(false); 0135 m_stack->setCurrentWidget(m_listView); 0136 } 0137 0138 void ViewStack::showIconView() { 0139 m_stack->setCurrentWidget(m_iconView); 0140 setIconSizeInterfaceVisible(true); 0141 } 0142 0143 void ViewStack::slotDecreaseIconSizeButtonClicked() { 0144 m_iconSizeSlider->setValue(m_iconSizeSlider->value() - LARGE_INCREMENT_ICON_SIZE); 0145 } 0146 0147 void ViewStack::slotIncreaseIconSizeButtonClicked() { 0148 m_iconSizeSlider->setValue(m_iconSizeSlider->value() + LARGE_INCREMENT_ICON_SIZE); 0149 } 0150 0151 void ViewStack::slotIconSizeSliderChanged(int size) { 0152 m_decreaseIconSizeButton->setEnabled(size > MIN_ENTRY_ICON_SIZE); 0153 m_increaseIconSizeButton->setEnabled(size < MAX_ENTRY_ICON_SIZE); 0154 m_iconSizeSlider->setToolTip(i18n("The current maximum icon size is %1.\nMove the slider to change it.", size)); 0155 Config::setMaxIconSize(size); 0156 m_iconView->setMaxAllowedIconWidth(size); 0157 } 0158 0159 void ViewStack::setIconSizeInterfaceVisible(bool visible) { 0160 m_decreaseIconSizeButton->setVisible(visible); 0161 m_increaseIconSizeButton->setVisible(visible); 0162 m_iconSizeSlider->setVisible(visible); 0163 }