diff --git a/kcm/src/resolutionslider.cpp b/kcm/src/resolutionslider.cpp index 7485125..b7cce77 100644 --- a/kcm/src/resolutionslider.cpp +++ b/kcm/src/resolutionslider.cpp @@ -1,168 +1,197 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . * */ #include "resolutionslider.h" #include "utils.h" #include #include #include #include #include #include static bool sizeLessThan(const QSize &sizeA, const QSize &sizeB) { return sizeA.width() * sizeA.height() < sizeB.width() * sizeB.height(); } ResolutionSlider::ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent) : QWidget(parent) , mOutput(output) { connect(output.data(), &KScreen::Output::currentModeIdChanged, this, &ResolutionSlider::slotOutputModeChanged); + connect(output.data(), &KScreen::Output::modesChanged, + this, &ResolutionSlider::init); - Q_FOREACH (const KScreen::ModePtr &mode, output->modes()) { + init(); +} + +ResolutionSlider::~ResolutionSlider() +{ +} + +void ResolutionSlider::init() +{ + mModes.clear(); + Q_FOREACH (const KScreen::ModePtr &mode, mOutput->modes()) { if (mModes.contains(mode->size())) { continue; } mModes << mode->size(); } qSort(mModes.begin(), mModes.end(), sizeLessThan); + delete layout(); + delete mSmallestLabel; + mSmallestLabel = nullptr; + delete mBiggestLabel; + mBiggestLabel = nullptr; + delete mCurrentLabel; + mCurrentLabel = nullptr; + delete mSlider; + mSlider = nullptr; + delete mComboBox; + mComboBox = nullptr; + QGridLayout *layout = new QGridLayout(this); int margin = layout->margin(); // Avoid double margins layout->setMargin(0); if (mModes.count() > 15) { std::reverse(mModes.begin(), mModes.end()); mComboBox = new QComboBox(this); mComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); mComboBox->setEditable(false); + int currentModeIndex = -1; + int preferredModeIndex = -1; Q_FOREACH (const QSize &size, mModes) { - const bool isCurrentMode = output->currentMode() && (output->currentMode()->size() == size); - const bool isPreferredMode = output->preferredMode() && (output->preferredMode()->size() == size); - const QIcon icon = isPreferredMode ? QIcon::fromTheme(QStringLiteral("favorite")) : QIcon(); - - mComboBox->addItem(icon, Utils::sizeToString(size)); - if (isCurrentMode || isPreferredMode) { - mComboBox->setCurrentIndex(mComboBox->count() - 1); + mComboBox->addItem(Utils::sizeToString(size)); + if (mOutput->currentMode() && (mOutput->currentMode()->size() == size)) { + currentModeIndex = mComboBox->count() - 1; + } else if (mOutput->preferredMode() && (mOutput->preferredMode()->size() == size)) { + preferredModeIndex = mComboBox->count() - 1; } } + if (currentModeIndex != -1) { + mComboBox->setCurrentIndex(currentModeIndex); + } else if (preferredModeIndex != -1) { + mComboBox->setCurrentIndex(preferredModeIndex); + } layout->addWidget(mComboBox, 0, 0, 1, 1); connect(mComboBox, static_cast(&QComboBox::currentIndexChanged), - this, &ResolutionSlider::slotValueChanged); + this, &ResolutionSlider::slotValueChanged, Qt::UniqueConnection); + + Q_EMIT resolutionChanged(mModes.at(mComboBox->currentIndex())); } else { mCurrentLabel = new QLabel(this); mCurrentLabel->setAlignment(Qt::AlignCenter); layout->addWidget(mCurrentLabel, 1, 0, 1, 3); if (mModes.isEmpty()) { mCurrentLabel->setText(i18n("No available resolutions")); } else if (mModes.count() == 1) { mCurrentLabel->setText(Utils::sizeToString(mModes.first())); } else { // No double margins left and right, but they are needed on top and bottom layout->setContentsMargins(0, margin, 0, margin); mSlider = new QSlider(Qt::Horizontal, this); mSlider->setTickInterval(1); mSlider->setTickPosition(QSlider::TicksBelow); mSlider->setSingleStep(1); mSlider->setPageStep(1); mSlider->setMinimum(0); mSlider->setMaximum(mModes.size() - 1); mSlider->setSingleStep(1); - if (output->currentMode()) { - mSlider->setValue(mModes.indexOf(output->currentMode()->size())); - } else if (output->preferredMode()) { - mSlider->setValue(mModes.indexOf(output->preferredMode()->size())); + if (mOutput->currentMode()) { + mSlider->setValue(mModes.indexOf(mOutput->currentMode()->size())); + } else if (mOutput->preferredMode()) { + mSlider->setValue(mModes.indexOf(mOutput->preferredMode()->size())); } else { mSlider->setValue(mSlider->maximum()); } layout->addWidget(mSlider, 0, 1); connect(mSlider, &QSlider::valueChanged, this, &ResolutionSlider::slotValueChanged); mSmallestLabel = new QLabel(this); mSmallestLabel->setText(Utils::sizeToString(mModes.first())); layout->addWidget(mSmallestLabel, 0, 0); mBiggestLabel = new QLabel(this); mBiggestLabel->setText(Utils::sizeToString(mModes.last())); layout->addWidget(mBiggestLabel, 0, 2); - mCurrentLabel->setText(Utils::sizeToString(mModes.at(mSlider->value()))); + const auto size = mModes.at(mSlider->value()); + mCurrentLabel->setText(Utils::sizeToString(size)); + Q_EMIT resolutionChanged(size); } } } -ResolutionSlider::~ResolutionSlider() -{ -} - QSize ResolutionSlider::currentResolution() const { if (mModes.isEmpty()) { return QSize(); } if (mModes.size() < 2) { return mModes.first(); } if (mSlider) { return mModes.at(mSlider->value()); } else { const int i = mComboBox->currentIndex(); return i > -1 ? mModes.at(i) : QSize(); } } void ResolutionSlider::slotOutputModeChanged() { if (!mOutput->currentMode()) { return; } if (mSlider) { mSlider->blockSignals(true); mSlider->setValue(mModes.indexOf(mOutput->currentMode()->size())); mSlider->blockSignals(false); } else if (mComboBox) { mComboBox->blockSignals(true); mComboBox->setCurrentIndex(mModes.indexOf(mOutput->currentMode()->size())); mComboBox->blockSignals(false); } } void ResolutionSlider::slotValueChanged(int value) { const QSize &size = mModes.at(value); if (mCurrentLabel) { mCurrentLabel->setText(Utils::sizeToString(size)); } Q_EMIT resolutionChanged(size); } diff --git a/kcm/src/resolutionslider.h b/kcm/src/resolutionslider.h index 504b479..cc45376 100644 --- a/kcm/src/resolutionslider.h +++ b/kcm/src/resolutionslider.h @@ -1,63 +1,65 @@ /* * Copyright 2013 Daniel Vrátil * * 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * 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, see . * */ #ifndef RESOLUTIONSLIDER_H #define RESOLUTIONSLIDER_H #include #include #include class QSlider; class QLabel; class QComboBox; class ResolutionSlider : public QWidget { Q_OBJECT public: explicit ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent = nullptr); ~ResolutionSlider() override; QSize currentResolution() const; Q_SIGNALS: void resolutionChanged(const QSize &size); private Q_SLOTS: void slotValueChanged(int); void slotOutputModeChanged(); private: + void init(); + KScreen::OutputPtr mOutput; QList mModes; QLabel *mSmallestLabel = nullptr; QLabel *mBiggestLabel = nullptr; QLabel *mCurrentLabel = nullptr; QSlider *mSlider = nullptr; QComboBox *mComboBox = nullptr; }; #endif // RESOLUTIONSLIDER_H diff --git a/plasma/plasma-applet-kscreen.desktop.cmake b/plasma/plasma-applet-kscreen.desktop.cmake new file mode 100644 index 0000000..1b69afd --- /dev/null +++ b/plasma/plasma-applet-kscreen.desktop.cmake @@ -0,0 +1,108 @@ +[Desktop Entry] +Name=Quick Display Configuration +Name[ar]=ضبط سريع للعرض +Name[bs]=Brza konfiguracija ekrana +Name[ca]=Configuració ràpida de la pantalla +Name[ca@valencia]=Configuració ràpida de la pantalla +Name[cs]=Rychlé nastavení zobrazení +Name[da]=Hurtig konfiguration af skærme +Name[de]=Schnelle Anzeige-Einrichtung +Name[el]=Γρήγορη διαμόρφωση οθόνης +Name[en_GB]=Quick Display Configuration +Name[es]=Configuración rápida de la pantalla +Name[et]=Ekraani kiirseadistamine +Name[eu]=Bistaratzaileen konfigurazio azkarra +Name[fi]=Näyttöasetusten pikasäätö +Name[fr]=Configuration rapide de l'affichage +Name[gl]=Configuración rápida da pantalla +Name[he]=הגדרות מסך מהירות +Name[hu]=Gyors megjelenítő-beállítás +Name[ia]=Configuration rapide de monstrator +Name[id]=Quick Display Configuration +Name[it]=Configurazione rapida dello schermo +Name[ko]=빠른 화면 설정 +Name[lt]=Greita ekrano konfigūracija +Name[nb]=Hurtig skjermoppsett +Name[nl]=Snel instellen van scherm +Name[nn]=Kjapt skjermoppsett +Name[pa]=ਤੁਰੰਤ ਡਿਸਪਲੇਅ ਸੰਰਚਨਾ +Name[pl]=Szybkie ustawienia ekranu +Name[pt]=Configuração Rápida do Ecrã +Name[pt_BR]=Configuração rápida da tela +Name[ro]=Configurare rapidă afișaj +Name[ru]=Быстрая настройка экрана +Name[sk]=Rýchle nastavenie obrazovky +Name[sl]=Hitre nastavitve zaslona +Name[sr]=Брзо подешавање екрана +Name[sr@ijekavian]=Брзо подешавање екрана +Name[sr@ijekavianlatin]=Brzo podešavanje ekrana +Name[sr@latin]=Brzo podešavanje ekrana +Name[sv]=Snabbinställning av skärm +Name[tr]=Hızlı Ekran Yapılandırması +Name[uk]=Швидке налаштовування дисплея +Name[x-test]=xxQuick Display Configurationxx +Name[zh_CN]=快捷显示管理 +Name[zh_TW]=快速顯示設定 +Comment=Quick configuration of a new display +Comment[ar]=ضبط سريع لعرض جديد +Comment[bs]=Brza konfiguracija novog ekrana +Comment[ca]=Configuració ràpida d'una nova pantalla +Comment[ca@valencia]=Configuració ràpida d'una nova pantalla +Comment[cs]=Rychlé nastavení nového zobrazení +Comment[da]=Hurtig konfiguration af en ny skærm +Comment[de]=Schnelle Einrichtung einer neuen Anzeige +Comment[el]=Γρήγορη διαμόρφωση μιας νέας οθόνης +Comment[en_GB]=Quick configuration of a new display +Comment[es]=Configuración rápida de una nueva pantalla +Comment[et]=Uue ekraani kiirseadistamine +Comment[eu]=Bistaratzaile berri baten konfigurazio azkarra +Comment[fi]=Näyttöasetusten pikasäätö +Comment[fr]=Configuration rapide d'un nouvel affichage +Comment[gl]=Configura rapidamente unha nova pantalla +Comment[he]=הגדרה מהירה של תצוגה חדשה +Comment[hu]=Új megjelenítők gyors beállítása +Comment[ia]=Configuration rapide de un nove monstrator +Comment[id]=Konfigurasi cepat dari sebuah displai baru +Comment[it]=Configurazione rapida di un nuovo schermo +Comment[ko]=새 디스플레이 빠른 설정 +Comment[lt]=Grupės naujo ekrano konfigūracija +Comment[nb]=Hurtig oppsett av en ny skjerm +Comment[nl]=Snel instellen van een nieuwe scherm +Comment[nn]=Kjapt oppsett av ny skjerm +Comment[pa]=ਨਵੇਂ ਡਿਸਪਲੇਅ ਲਈ ਤੁਰੰਤ ਸੰਰਚਨਾ +Comment[pl]=Szybkie ustawienia nowego ekranu +Comment[pt]=Configuração rápida de um novo ecrã +Comment[pt_BR]=Configuração rápida de uma nova tela +Comment[ro]=Configurare rapidă a unui nou afișaj +Comment[ru]=Быстрая настройка нового экрана +Comment[sk]=Rýchle nastavenie novej obrazovky +Comment[sl]=Hitre nastavitve novega zaslona +Comment[sr]=Брзо подешавање за нов екран +Comment[sr@ijekavian]=Брзо подешавање за нов екран +Comment[sr@ijekavianlatin]=Brzo podešavanje za nov ekran +Comment[sr@latin]=Brzo podešavanje za nov ekran +Comment[sv]=Snabbinställning av en ny skärm +Comment[tr]=Yeni bir ekranın hızlı yapılandırması +Comment[uk]=Швидке налаштовування нового дисплея +Comment[x-test]=xxQuick configuration of a new displayxx +Comment[zh_CN]=快捷配置新显示器 +Comment[zh_TW]=快速設定新的顯示 + +Icon=preferences-desktop-display-randr +Type=Service +X-KDE-ServiceTypes=Plasma/Applet,Plasma/PopupApplet + +X-Plasma-DefaultSize=290,150 +X-Plasma-NotificationArea=true +X-Plasma-ConfigPlugins=kscreen + +X-KDE-Library=plasma_applet_kscreen +X-KDE-PluginInfo-Author=Dan Vrátil +X-KDE-PluginInfo-Email=dvratil@redhat.com +X-KDE-PluginInfo-Name=org.kde.plasma.kscreen +X-KDE-PluginInfo-Version=@KSCREEN_VERSION@ +X-KDE-PluginInfo-Website=http://www.kde.org +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true