configdialog.cpp 7.22 KB
Newer Older
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2 3
/*
Gwenview: an image viewer
Aurélien Gâteau's avatar
Aurélien Gâteau committed
4
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
5 6 7 8 9 10 11 12 13 14 15 16 17

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 20 21 22 23 24 25 26

*/
// Self
#include "configdialog.h"

// Qt

// KDE
David Edmundson's avatar
David Edmundson committed
27
#include <KLocalizedString>
28 29

// Local
30
#include <lib/gwenviewconfig.h>
Laurent Montel's avatar
Laurent Montel committed
31
#include <QFontDatabase>
32

33 34
namespace Gwenview
{
35

36
template <class Ui>
37 38 39 40
QWidget* setupPage(Ui& ui)
{
    QWidget* widget = new QWidget;
    ui.setupUi(widget);
Laurent Montel's avatar
Laurent Montel committed
41
    widget->layout()->setContentsMargins(0, 0, 0, 0);
42
    return widget;
43
}
44 45

ConfigDialog::ConfigDialog(QWidget* parent)
Aurélien Gâteau's avatar
Aurélien Gâteau committed
46
: KConfigDialog(parent, "Settings", GwenviewConfig::self())
47 48
{
    setFaceType(KPageDialog::List);
49

50 51 52 53
    QWidget* widget;
    KPageWidgetItem* pageItem;

    // General
Frederik Gladhorn's avatar
Frederik Gladhorn committed
54
    widget = setupPage(mGeneralConfigPage);
55 56
    
    mThumbnailActionsGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
57
    mThumbnailActionsGroup->setObjectName(QStringLiteral("kcfg_ThumbnailActions"));
58 59 60 61
    mThumbnailActionsGroup->addButton(mGeneralConfigPage.allButtonsThumbnailActionsRadioButton, int(ThumbnailActions::AllButtons));
    mThumbnailActionsGroup->addButton(mGeneralConfigPage.selectionOnlyThumbnailActionsRadioButton, int(ThumbnailActions::ShowSelectionButtonOnly));
    mThumbnailActionsGroup->addButton(mGeneralConfigPage.noneThumbnailActionsRadioButton, int(ThumbnailActions::None));

62
    pageItem = addPage(widget, i18n("General"));
Laurent Montel's avatar
Laurent Montel committed
63
    pageItem->setIcon(QIcon::fromTheme(QStringLiteral("gwenview")));
Laurent Montel's avatar
Laurent Montel committed
64
    connect(mGeneralConfigPage.kcfg_ViewBackgroundValue, &QAbstractSlider::valueChanged, this, &ConfigDialog::updateViewBackgroundFrame);
65 66 67 68 69
    connect(mGeneralConfigPage.kcfg_JPEGQuality, &QAbstractSlider::valueChanged, this, [=] (int value) {mGeneralConfigPage.jpegQualitySpinner->setValue(value);});
    connect(mGeneralConfigPage.jpegQualitySpinner, QOverload<int>::of(&QSpinBox::valueChanged), this, [=] (int value) {mGeneralConfigPage.kcfg_JPEGQuality->setValue(value);});
    mGeneralConfigPage.jpegQualitySpinner->setValue(mGeneralConfigPage.kcfg_JPEGQuality->value());
    mGeneralConfigPage.backgroundValueFrame->setMinimumWidth(mGeneralConfigPage.jpegQualitySpinner->width());
    
70 71 72 73 74
    mGeneralConfigPage.kcfg_AutoplayVideos->setEnabled(mGeneralConfigPage.kcfg_ListVideos->isChecked());
    connect(mGeneralConfigPage.kcfg_ListVideos, &QCheckBox::stateChanged, [=](const int &state) {
        mGeneralConfigPage.kcfg_AutoplayVideos->setEnabled(state == Qt::Checked);
    });

75
    // Image View
Frederik Gladhorn's avatar
Frederik Gladhorn committed
76 77 78
    widget = setupPage(mImageViewConfigPage);

    mAlphaBackgroundModeGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
79
    mAlphaBackgroundModeGroup->setObjectName(QStringLiteral("kcfg_AlphaBackgroundMode"));
80
    mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.surroundingRadioButton, int(AbstractImageView::AlphaBackgroundNone));
81 82
    mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.checkBoardRadioButton, int(AbstractImageView::AlphaBackgroundCheckBoard));
    mAlphaBackgroundModeGroup->addButton(mImageViewConfigPage.solidColorRadioButton, int(AbstractImageView::AlphaBackgroundSolid));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
83 84

    mWheelBehaviorGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
85
    mWheelBehaviorGroup->setObjectName(QStringLiteral("kcfg_MouseWheelBehavior"));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
86 87
    mWheelBehaviorGroup->addButton(mImageViewConfigPage.mouseWheelScrollRadioButton, int(MouseWheelBehavior::Scroll));
    mWheelBehaviorGroup->addButton(mImageViewConfigPage.mouseWheelBrowseRadioButton, int(MouseWheelBehavior::Browse));
Chris Suran's avatar
Chris Suran committed
88
    mWheelBehaviorGroup->addButton(mImageViewConfigPage.mouseWheelZoomRadioButton, int(MouseWheelBehavior::Zoom));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
89 90

    mAnimationMethodGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
91
    mAnimationMethodGroup->setObjectName(QStringLiteral("kcfg_AnimationMethod"));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
92 93 94 95 96
    mAnimationMethodGroup->addButton(mImageViewConfigPage.glAnimationRadioButton, int(DocumentView::GLAnimation));
    mAnimationMethodGroup->addButton(mImageViewConfigPage.softwareAnimationRadioButton, int(DocumentView::SoftwareAnimation));
    mAnimationMethodGroup->addButton(mImageViewConfigPage.noAnimationRadioButton, int(DocumentView::NoAnimation));

    mZoomModeGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
97
    mZoomModeGroup->setObjectName(QStringLiteral("kcfg_ZoomMode"));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
98 99 100 101 102
    mZoomModeGroup->addButton(mImageViewConfigPage.autofitZoomModeRadioButton, int(ZoomMode::Autofit));
    mZoomModeGroup->addButton(mImageViewConfigPage.keepSameZoomModeRadioButton, int(ZoomMode::KeepSame));
    mZoomModeGroup->addButton(mImageViewConfigPage.individualZoomModeRadioButton, int(ZoomMode::Individual));

    mThumbnailBarOrientationGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
103
    mThumbnailBarOrientationGroup->setObjectName(QStringLiteral("kcfg_ThumbnailBarOrientation"));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
104 105
    mThumbnailBarOrientationGroup->addButton(mImageViewConfigPage.horizontalRadioButton, int(Qt::Horizontal));
    mThumbnailBarOrientationGroup->addButton(mImageViewConfigPage.verticalRadioButton, int(Qt::Vertical));
106 107

    pageItem = addPage(widget, i18n("Image View"));
Laurent Montel's avatar
Laurent Montel committed
108
    pageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-display-color")));
109 110

    // Advanced
Frederik Gladhorn's avatar
Frederik Gladhorn committed
111
    widget = setupPage(mAdvancedConfigPage);
112 113

    mRenderingIntentGroup = new InvisibleButtonGroup(widget);
Laurent Montel's avatar
Laurent Montel committed
114
    mRenderingIntentGroup->setObjectName(QStringLiteral("kcfg_RenderingIntent"));
115 116 117
    mRenderingIntentGroup->addButton(mAdvancedConfigPage.relativeRenderingIntentRadioButton, int(RenderingIntent::Relative));
    mRenderingIntentGroup->addButton(mAdvancedConfigPage.perceptualRenderingIntentRadioButton, int(RenderingIntent::Perceptual));

118
    pageItem = addPage(widget, i18n("Advanced"));
Laurent Montel's avatar
Laurent Montel committed
119
    pageItem->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other")));
Frederik Gladhorn's avatar
Frederik Gladhorn committed
120
    mAdvancedConfigPage.cacheHelpLabel->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
121 122
    mAdvancedConfigPage.perceptualHelpLabel->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
    mAdvancedConfigPage.relativeHelpLabel->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
123 124
    mAdvancedConfigPage.colorProfileHelpLabel->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));

125 126

    updateViewBackgroundFrame();
127 128
}

129 130
void ConfigDialog::updateViewBackgroundFrame()
{
Laurent Montel's avatar
Laurent Montel committed
131 132 133
    const QColor color = QColor::fromHsv(0, 0, mGeneralConfigPage.kcfg_ViewBackgroundValue->value());
    const QString css =
        QStringLiteral(
134 135 136 137 138 139 140
            "background-color: %1;"
            "border-radius: 5px;"
            "border: 1px solid %1;")
        .arg(color.name());
    // When using Oxygen, setting the background color via palette causes the
    // pixels outside the frame to be painted with the new background color as
    // well. Using CSS works more like expected.
Frederik Gladhorn's avatar
Frederik Gladhorn committed
141
    mGeneralConfigPage.backgroundValueFrame->setStyleSheet(css);
142 143
}

144
} // namespace