diff --git a/lxqt-config-monitor/CMakeLists.txt b/lxqt-config-monitor/CMakeLists.txt index 7020e60e3..a24708f3c 100644 --- a/lxqt-config-monitor/CMakeLists.txt +++ b/lxqt-config-monitor/CMakeLists.txt @@ -1,18 +1,19 @@ project(lxqt-config-monitor) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + include_directories ( "${CMAKE_CURRENT_BINARY_DIR}" ${LXQT_INCLUDE_DIRS} ) -find_package(Qt5Svg REQUIRED) +find_package(KF5Screen REQUIRED) set(H_FILES main.h monitorsettingsdialog.h monitor.h monitorwidget.h - xrandr.h monitorpicture.h quickoptions.h applydialog.h @@ -21,7 +22,6 @@ set(H_FILES set(CPP_FILES main.cpp monitorsettingsdialog.cpp - xrandr.cpp monitor.cpp monitorwidget.cpp timeoutdialog.cpp @@ -83,10 +83,10 @@ add_executable(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::X11Extras - Qt5::Svg + KF5::Screen ${LXQT_LIBRARIES} ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) install(FILES ${DESKTOP_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications") -install(FILES ${ICON_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/lxqt/icons/") \ No newline at end of file +install(FILES ${ICON_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/lxqt/icons/") diff --git a/lxqt-config-monitor/main.cpp b/lxqt-config-monitor/main.cpp index b407c9574..967356148 100644 --- a/lxqt-config-monitor/main.cpp +++ b/lxqt-config-monitor/main.cpp @@ -16,20 +16,16 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #include "main.h" #include #include #include #include #include "monitorsettingsdialog.h" -#include "quickoptions.h" -#include "xrandr.h" -#include "applydialog.h" int main(int argc, char** argv) { LxQt::SingleApplication app(argc, argv); - + QByteArray configName = qgetenv("LXQT_SESSION_CONFIG"); if(configName.isEmpty()) configName = "MonitorSettings"; @@ -38,7 +34,7 @@ int main(int argc, char** argv) { dlg.setButtons(QDialogButtonBox::QDialogButtonBox::Apply|QDialogButtonBox::Close); app.setActivationWindow(&dlg); dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display")); - + XRandRBackend *xrandr = new XRandRBackend(); MonitorSettingsDialog *monitorSettingsDialog = new MonitorSettingsDialog(xrandr, &settings); monitorSettingsDialog->connect(&dlg, SIGNAL(clicked(QDialogButtonBox::StandardButton)), SLOT(processClickedFromDialog(QDialogButtonBox::StandardButton))); @@ -54,22 +50,23 @@ int main(int argc, char** argv) { dlg.addPage(quickOptions, QObject::tr("Quick Options"), "format-justify-left"); } } - + dlg.addPage(monitorSettingsDialog, QObject::tr("Settings"), "preferences-desktop-display"); - + ApplyDialog *apply = new ApplyDialog(&settings); apply->setHardwareIdentifier(monitorSettingsDialog->getHardwareIdentifier()); // monitorSettingsDialog->connect(apply->ui.apply, SIGNAL(clicked(bool)), SLOT(applySettings())); monitorSettingsDialog->connect(apply->ui.save, SIGNAL(clicked(bool)), SLOT(saveSettings())); apply->connect(monitorSettingsDialog, SIGNAL(settingsSaved()), SLOT(loadSettings())); - + dlg.addPage(apply, QObject::tr("Save settings"), "system-run"); - + QObject::connect(&dlg, SIGNAL(reset()), &dlg, SLOT(accept())); - if(QDialog::Accepted == dlg.exec() ) { - main(argc, argv); - } - - return 0; + MonitorSettingsDialog dlg; + app.setActivationWindow(&dlg); + dlg.setWindowIcon(QIcon::fromTheme("preferences-desktop-display")); + dlg.show(); + + return app.exec(); } diff --git a/lxqt-config-monitor/mainwindow.ui b/lxqt-config-monitor/mainwindow.ui index afa434bbb..6d6a6845f 100644 --- a/lxqt-config-monitor/mainwindow.ui +++ b/lxqt-config-monitor/mainwindow.ui @@ -20,83 +20,49 @@ - - - - - - - - - 0 - 1 - - - - Qt::ScrollBarAlwaysOff - - - - - - - - 1 - 1 - - - - - - - - - - - - Unify all monitors - - - - - - - Monitor Position - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Primary monitor: - - - - - - - - - - - - - - - + + + + + + 0 + 1 + + + + Qt::ScrollBarAlwaysOff + + + QListView::Adjust + + + + + + + + 1 + 1 + + + + + 100 + 0 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Close + @@ -110,12 +76,24 @@ setCurrentIndex(int) - 146 - 146 + 126 + 181 + + + + + buttonBox + rejected() + MonitorSettingsDialog + reject() + + + 338 + 439 - 394 - 146 + 286 + 257 diff --git a/lxqt-config-monitor/monitor.cpp b/lxqt-config-monitor/monitor.cpp index f8e8a4ff0..03969862b 100644 --- a/lxqt-config-monitor/monitor.cpp +++ b/lxqt-config-monitor/monitor.cpp @@ -21,12 +21,15 @@ bool MonitorInfo::LVDS_Ok = false; -bool MonitorSettingsBackend::isUnified(const QList< MonitorInfo* > monitors) { - Q_FOREACH(MonitorInfo * monitor, monitors) { - if(monitor->position != MonitorSettings::None) - return false; +QSize sizeFromString(QString str) { + int width = 0; + int height = 0; + int x = str.indexOf('x'); + if(x > 0) { + width = str.left(x).toInt(); + height = str.mid(x + 1).toInt(); } - return true; + return QSize(width, height); } MonitorSettings::MonitorSettings(QObject* parent): QObject(parent) { diff --git a/lxqt-config-monitor/monitor.h b/lxqt-config-monitor/monitor.h index 2c2e84ed5..637cd5c9e 100644 --- a/lxqt-config-monitor/monitor.h +++ b/lxqt-config-monitor/monitor.h @@ -24,6 +24,8 @@ #include #include #include +#include + //Settings to pass to backend class MonitorSettings: public QObject { @@ -55,8 +57,10 @@ class MonitorMode: public QObject { // Monitor information from backend class MonitorInfo: public MonitorSettings { - Q_OBJECT + Q_OBJECT public: + KScreen::ConfigPtr mConfig; + MonitorInfo(QObject* parent = 0); QStringList modes; // Modes of this monitor in order QHash monitorModes; // Rates suported by each mode @@ -69,18 +73,6 @@ class MonitorInfo: public MonitorSettings { QString humanReadableName(); }; - -class MonitorSettingsBackend: public QObject { - Q_OBJECT -public: - virtual QList getMonitorsInfo() = 0; - virtual bool setMonitorsSettings(const QList monitors) = 0; - virtual QString getCommand(const QList monitors) = 0; - virtual bool isUnified(const QList monitors); -}; - - - /**Gets size from string rate. String rate format is "widthxheight". Example: 800x600*/ QSize sizeFromString(QString str); diff --git a/lxqt-config-monitor/monitorpicture.cpp b/lxqt-config-monitor/monitorpicture.cpp index 812f3cb32..8f9df0f83 100644 --- a/lxqt-config-monitor/monitorpicture.cpp +++ b/lxqt-config-monitor/monitorpicture.cpp @@ -36,7 +36,7 @@ void MonitorPictureDialog::updateMonitorWidgets(QString primaryMonitor) { int x0, y0; x0 = y0 =0; Q_FOREACH(MonitorPicture * picture, pictures) { - if( picture->monitorWidget->monitorInfo->name == primaryMonitor || primaryMonitor=="") { + if( picture->monitorWidget->output->name() == primaryMonitor || primaryMonitor=="") { x0 = picture->monitorWidget->ui.xPosSpinBox->value() + picture->pos().x(); y0 = picture->monitorWidget->ui.yPosSpinBox->value() + picture->pos().y(); break; @@ -69,31 +69,18 @@ MonitorPicture::MonitorPicture(QGraphicsItem * parent, MonitorWidget *monitorWid setRect(x, y, currentSizeWidth, currentSizeHeight); originX = x; originY = y; - - - QSvgRenderer *renderer = new QSvgRenderer(QLatin1String(ICON_PATH "monitor.svg")); - svgItem = new QGraphicsSvgItem(); - svgItem->setSharedRenderer(renderer); - svgItem->setX(x); - svgItem->setY(y); - svgItem->setOpacity(0.7); - svgItem->setParentItem(this); - - - textItem = new QGraphicsTextItem(monitorWidget->monitorInfo->name, this); - textItem->setDefaultTextColor(Qt::white); + setPen(QPen(Qt::black, 20)); + textItem = new QGraphicsTextItem(monitorWidget->output->name(), this); textItem->setX(x); textItem->setY(y); textItem->setParentItem(this); - setPen(QPen(Qt::black, 20)); - + adjustNameSize(); } void MonitorPicture::adjustNameSize() { - prepareGeometryChange(); - qreal fontWidth = QFontMetrics(textItem->font()).width(monitorWidget->monitorInfo->name+" "); + qreal fontWidth = QFontMetrics(textItem->font()).width(monitorWidget->output->name() + " "); textItem->setScale((qreal)this->rect().width()/fontWidth); QTransform transform; qreal width = qAbs(this->rect().width()/svgItem->boundingRect().width()); @@ -130,7 +117,7 @@ void MonitorPicture::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) ////////////////////////////////////////////////////////////////////////////////// // Move picture to nearest picture procedure. -// Read magnetic_attraction.html for more info about the algorithm used. +// Read magnetic_attraction.html for more info about the algorithm used. ////////////////////////////////////////////////////////////////////////////////// struct Parameters { @@ -223,14 +210,14 @@ static Result_moveMonitorPictureToNearest compareTwoMonitors(MonitorPicture* mon if(params.t1>=0.0 && params.t1<=1.0 && params.t2>=0.0 && params.t2<=1.0) { if(t2<0) {t2 = params.t1; P2 = params.cutPoint;} } - + if(t1>t2) { //Monitor outside result.vector = P1-P2; result.ok = false; } else { result.ok = true; } - + return result; } diff --git a/lxqt-config-monitor/monitorsettingsdialog.cpp b/lxqt-config-monitor/monitorsettingsdialog.cpp index e032cb918..1a44c27f7 100644 --- a/lxqt-config-monitor/monitorsettingsdialog.cpp +++ b/lxqt-config-monitor/monitorsettingsdialog.cpp @@ -17,39 +17,30 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #include "monitorsettingsdialog.h" -#include #include #include #include -#include -#include #include -#include -#include #include +#include #include #include #include -#include -#include -#include +#include +#include #include "monitorwidget.h" #include "timeoutdialog.h" -#include "xrandr.h" #include "monitorpicture.h" -MonitorSettingsDialog::MonitorSettingsDialog(MonitorSettingsBackend* backend, LxQt::Settings *applicationSettings): - QDialog(NULL, 0), - LVDS(NULL) { - timeoutDialog = NULL; - timer = NULL; - this->applicationSettings = applicationSettings; - this->backend = backend; - backend->setParent(this); - setupUi(); + +MonitorSettingsDialog::MonitorSettingsDialog(): + QDialog(NULL, 0) +{ + timeoutDialog = NULL; + timer = NULL; + setupUi(); } @@ -57,263 +48,66 @@ MonitorSettingsDialog::~MonitorSettingsDialog() { } -void MonitorSettingsDialog::deleteTimeoutData() { - timeoutDialog = NULL; - Q_FOREACH(MonitorInfo * monitorInfo, timeoutSettings) { - delete monitorInfo; - } - timeoutSettings.clear(); -} - -void MonitorSettingsDialog::onCancelSettings() { - // restore the old settings - QList settings; - Q_FOREACH(MonitorInfo * monitorInfo, timeoutSettings) { - settings.append((MonitorSettings*)monitorInfo); - } - backend->setMonitorsSettings(settings); - deleteTimeoutData(); -} +void MonitorSettingsDialog::configReceived(KScreen::ConfigOperation *op) { + mConfig = qobject_cast(op)->config(); -QList MonitorSettingsDialog::getMonitorsSettings() { - // Build list of monitor and their settings - QList settings; - Q_FOREACH(MonitorWidget * monitor, monitors) { - MonitorSettings* s = monitor->getSettings(); - settings.append(s); - if(ui.primaryCombo->currentText() == monitor->monitorInfo->name) - s->primaryOk = true; - } - if(ui.unify->isChecked()) { - Q_FOREACH(MonitorSettings * s, settings) { - s->position = MonitorSettings::None; + KScreen::OutputList outputs = mConfig->outputs(); + Q_FOREACH(const KScreen::OutputPtr &output, outputs) { + if (output->isConnected()) { + MonitorWidget* monitor = new MonitorWidget(output, mConfig, this); + ui.monitorList->addItem(output->name()); + ui.stackedWidget->addWidget(monitor); + } } - } - return settings; -} -void MonitorSettingsDialog::setMonitorsConfig() { - deleteTimeoutData(); - timeoutSettings = backend->getMonitorsInfo(); - // Show timeout dialog - timeoutDialog = new TimeoutDialog(this); - connect(timeoutDialog, SIGNAL(rejected()), this, SLOT(onCancelSettings())); - connect(timeoutDialog, SIGNAL(finished(int)), timeoutDialog, SLOT(deleteLater())); - // Build list of monitor and their settings - QList settings = getMonitorsSettings(); - backend->setMonitorsSettings(settings); - Q_FOREACH(MonitorSettings * s, settings) { - delete s; - } - timeoutDialog->show(); + ui.monitorList->setMaximumWidth(ui.monitorList->sizeHintForColumn(0) + style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 40); + ui.monitorList->setCurrentRow(0); + adjustSize(); + //TODO: ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); } -// turn on both laptop LCD and the external monitor -void MonitorSettingsDialog::onUseBoth() { - if(monitors.length() == 0) - return; - ui.unify->setChecked(true); - MonitorWidget* monitor = monitors[0]; - bool ok; - QString mode; - for(int i = 0; i < monitor->monitorInfo->modes.length(); i++) { - mode = monitor->monitorInfo->modes[i]; - ok = true; - Q_FOREACH(MonitorWidget * monitor2, monitors) { - ok = ok && monitor2->monitorInfo->modes.contains(mode); - } - if(ok) - break; - } - qDebug() << "Mode selected" << mode << ok; - Q_FOREACH(MonitorWidget * monitor2, monitors) { - int index = monitor2->monitorInfo->modes.indexOf(mode) + 1; - if(monitor2->ui.resolutionCombo->count() > index) - monitor2->ui.resolutionCombo->setCurrentIndex(index); - else - monitor2->chooseMaxResolution(); - monitor2->enableMonitor(true); - qDebug() << "Mode selected index" << index << "Mode" << monitor->ui.resolutionCombo->currentText(); - } - setMonitorsConfig(); -} -// external monitor only -void MonitorSettingsDialog::onExternalOnly() { - Q_FOREACH(MonitorWidget * monitor, monitors) { - monitor->chooseMaxResolution(); - monitor->enableMonitor(monitor != LVDS); - } - setMonitorsConfig(); +void MonitorSettingsDialog::deleteTimeoutData() { + // TODO Wipe old settings } -// laptop panel - LVDS only -void MonitorSettingsDialog::onLaptopOnly() { - Q_FOREACH(MonitorWidget * monitor, monitors) { - monitor->chooseMaxResolution(); - monitor->enableMonitor(monitor == LVDS); - } - setMonitorsConfig(); -} +/** + * User wants to revert new settings + */ +void MonitorSettingsDialog::onCancelSettings() { -void MonitorSettingsDialog::onExtended() { - ui.unify->setChecked(false); - int virtualWidth = 0; - Q_FOREACH(MonitorWidget * monitor, monitors) { - monitor->chooseMaxResolution(); - monitor->enableMonitor(true); - monitor->disablePositionOption(false); - QString modeName = monitor->ui.resolutionCombo->currentText(); - int modeWidth = monitor->monitorInfo->monitorModes[modeName]->width; - monitor->ui.xPosSpinBox->setValue(virtualWidth); - monitor->ui.yPosSpinBox->setValue(0); - virtualWidth+=modeWidth; - } - setMonitorsConfig(); } -void MonitorSettingsDialog::setupUi() { - ui.setupUi(this); - connect(ui.positionPushButton, SIGNAL(clicked()), SLOT(onPositionButtonClicked())); - - // Get monitors information - QList monitorsInfo = backend->getMonitorsInfo(); - - // Search if LVSD monitor is connected - hardwareIdentifier = ""; - Q_FOREACH(MonitorInfo * monitorInfo, monitorsInfo) { - hardwareIdentifier+=monitorInfo->edid; - if(! LVDS && (monitorInfo->name.startsWith("LVDS") || monitorInfo->name.startsWith("PANEL"))) { - MonitorInfo::LVDS_Ok = true; - break; - } - } - - int i = 0; - connect(ui.unify, SIGNAL(toggled(bool)), this, SLOT(disablePositionOption(bool))); - Q_FOREACH(MonitorInfo * monitorInfo, monitorsInfo) { - ui.primaryCombo->addItem(monitorInfo->name); - if(monitorInfo->primaryOk) - ui.primaryCombo->setCurrentIndex(ui.primaryCombo->findText(monitorInfo->name)); +/** + * Apply the settings + */ - qDebug() << "Monitor" << monitorInfo->name; - MonitorWidget* monitor = new MonitorWidget(monitorInfo, monitorsInfo, this); - QString title = QString("Monitor %1: %2 (%3) %4") - .arg(i + 1) - .arg(monitor->monitorInfo->name) - .arg(monitor->monitorInfo->humanReadableName()) - .arg(monitor->monitorInfo->vendor); - qDebug() << "Monitor" << title; - monitor->setTitle(title); +void MonitorSettingsDialog::setMonitorsConfig() { + if (!mConfig) return; + KScreen::SetConfigOperation(*mConfig); +} - connect(ui.unify, SIGNAL(toggled(bool)), monitor, SLOT(disablePositionOption(bool))); - monitors.append(monitor); - if(! LVDS && (monitorInfo->name.startsWith("LVDS") || monitorInfo->name.startsWith("PANEL"))) { - LVDS = monitor; - } - ui.stackedWidget->addWidget(monitor); - ui.monitorList->addItem(monitor->monitorInfo->name); - ++i; - } - ui.monitorList->setCurrentRow(0); - // set the max width of the list widget to the maximal width of its rows + the width of a vertical scrollbar. - ui.monitorList->setMaximumWidth(ui.monitorList->sizeHintForColumn(0) + style()->pixelMetric(QStyle::PM_ScrollBarExtent) + 40); - // are the monitors unified? - if(monitorsInfo.length() > 1) - ui.unify->setChecked(backend->isUnified(monitorsInfo)); - else {// disable the option if we only have one monitor - ui.unify->setEnabled(false); - ui.positionPushButton->setEnabled(false); - } +void MonitorSettingsDialog::setupUi() { + ui.setupUi(this); - // If this is a laptop and there is an external monitor, offer quick options - if(monitors.length() == 2) { - // If there is only two monitors,offer quick options - if(! LVDS) { - LVDS = monitors[0]; - } - } + KScreen::GetConfigOperation *op = new KScreen::GetConfigOperation(); + connect(op, &KScreen::GetConfigOperation::finished, [&](KScreen::ConfigOperation *op) { + configReceived(op); + }); - adjustSize(); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onDialogButtonClicked(QAbstractButton*))); } void MonitorSettingsDialog::accept() { - setMonitorsConfig(); - QDialog::accept(); -} - -void MonitorSettingsDialog::disablePositionOption(bool disable) { - ui.positionPushButton->setEnabled(!disable); -} - -void MonitorSettingsDialog::onPositionButtonClicked() { - MonitorPictureDialog *dialog = new MonitorPictureDialog(this); - dialog->setScene(monitors); - dialog->exec(); - dialog->updateMonitorWidgets(ui.primaryCombo->currentText()); - delete dialog; -} - -void MonitorSettingsDialog::applySettings() { setMonitorsConfig(); + QDialog::accept(); } -void MonitorSettingsDialog::saveSettings() { - // Save config and exit - QMessageBox msgBox; - msgBox.setText(tr("Do you want to save changes?")); - msgBox.setInformativeText(tr("Please, check the settings before saving.")); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - if( ret == QMessageBox::Cancel ) - return; - bool ok; - QString configName = QInputDialog::getText(this, tr("Name"), - tr("Name:"), QLineEdit::Normal, - tr("Actual"), &ok); - if (!ok || configName.isEmpty()) - return; - QList settings = getMonitorsSettings(); - QString cmd = backend->getCommand(settings); - Q_FOREACH(MonitorSettings * s, settings) { - delete s; - } - QString desktop = QString("[Desktop Entry]\n" - "Type=Application\n" - "Name=LXQt-config-monitor autostart\n" - "Comment=Autostart monitor settings for LXQt-config-monitor\n" - "Exec=%1\n" - "OnlyShowIn=LXQt\n").arg(cmd); - // Check if ~/.config/autostart/ exists - ok = true; - QFileInfo fileInfo(QDir::homePath() + "/.config/autostart/"); - if( ! fileInfo.exists() ) - ok = QDir::root().mkpath(QDir::homePath() + "/.config/autostart/"); - QFile file(QDir::homePath() + "/.config/autostart/lxqt-config-monitor-autostart.desktop"); - if(ok) - ok = file.open(QIODevice::WriteOnly | QIODevice::Text); - if(!ok) { - QMessageBox::critical(this, tr("Error"), tr("Config can not be saved")); - return; +void MonitorSettingsDialog::onDialogButtonClicked(QAbstractButton* button) { + if(ui.buttonBox->standardButton(button) == QDialogButtonBox::Apply) { + setMonitorsConfig(); } - QTextStream out(&file); - out << desktop; - out.flush(); - file.close(); - - // Save config in applicationSettings - applicationSettings->beginGroup("configMonitor"); - QJsonArray savedConfigs = QJsonDocument::fromJson(applicationSettings->value("saved").toByteArray()).array(); - QJsonObject monitorConfig; - monitorConfig["hardwareIdentifier"] = hardwareIdentifier; - monitorConfig["command"] = cmd; - monitorConfig["name"] = configName; - savedConfigs.append(monitorConfig); - applicationSettings->setValue("saved", QVariant(QJsonDocument(savedConfigs).toJson())); - applicationSettings->endGroup(); - emit(settingsSaved()); } #include diff --git a/lxqt-config-monitor/monitorsettingsdialog.h b/lxqt-config-monitor/monitorsettingsdialog.h index 0976ab022..3b7271b5f 100644 --- a/lxqt-config-monitor/monitorsettingsdialog.h +++ b/lxqt-config-monitor/monitorsettingsdialog.h @@ -17,16 +17,14 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #ifndef MONITORSETTINGSDIALOG_H #define MONITORSETTINGSDIALOG_H #include -#include -#include +#include #include "ui_mainwindow.h" #include "monitor.h" -#include "monitorwidget.h" + class TimeoutDialog; class QTimer; @@ -35,7 +33,7 @@ class MonitorSettingsDialog: public QDialog { Q_OBJECT public: - MonitorSettingsDialog(MonitorSettingsBackend* backend, LxQt::Settings *applicationSettings); + MonitorSettingsDialog(); virtual ~MonitorSettingsDialog(); virtual void accept(); QString getHardwareIdentifier(); @@ -59,28 +57,23 @@ public Q_SLOTS: private: void setMonitorsConfig(); void setupUi(); - QList getMonitorsSettings(); void deleteTimeoutData(); // Used to delete data from TimeoutDialog private Q_SLOTS: + void configReceived(KScreen::ConfigOperation *op); + // Timeout dialog signals void onCancelSettings(); - void onPositionButtonClicked(); - void disablePositionOption(bool disable); + void onDialogButtonClicked(QAbstractButton* button); private: Ui::MonitorSettingsDialog ui; - QList monitors; - MonitorWidget* LVDS; - MonitorSettingsBackend* backend; + KScreen::ConfigPtr mConfig; // TimeoutDialog data TimeoutDialog* timeoutDialog; QTimer* timer; - QList timeoutSettings; - LxQt::Settings *applicationSettings; - QString hardwareIdentifier; }; #endif // MONITORSETTINGSDIALOG_H diff --git a/lxqt-config-monitor/monitorwidget.cpp b/lxqt-config-monitor/monitorwidget.cpp index e69ecd75a..eb6285ed6 100644 --- a/lxqt-config-monitor/monitorwidget.cpp +++ b/lxqt-config-monitor/monitorwidget.cpp @@ -20,105 +20,96 @@ #include "monitorwidget.h" #include "monitor.h" #include +#include +#include -MonitorWidget::MonitorWidget(MonitorInfo* monitor, const QList monitorsInfo, QWidget* parent): - QGroupBox(parent) { - ui.enabled = NULL; - monitorInfo = monitor; - monitor->setParent(this); // take the ownership - - ui.setupUi(this); - - if(monitorsInfo.length() == 1) { - disablePositionOption(true); - - // turn off screen is not allowed since there should be at least one monitor available. - ui.enabled->setEnabled(false); - } - - ui.xPosSpinBox->setValue(monitor->xPos); - ui.yPosSpinBox->setValue(monitor->yPos); - - if(monitor->enabledOk) - ui.enabled->setChecked(true); - - connect(ui.resolutionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onResolutionChanged(int))); - ui.resolutionCombo->addItem(tr("Auto")); - Q_FOREACH(QString _mode_line, monitor->modes) { - QVariant monitorModeInfo = QVariant::fromValue(monitor->monitorModes[_mode_line]); - ui.resolutionCombo->addItem(_mode_line, monitorModeInfo); - } - - - if(!monitor->currentMode.isEmpty()) - ui.resolutionCombo->setCurrentIndex(ui.resolutionCombo->findText(monitor->currentMode)); - else - ui.resolutionCombo->setCurrentIndex(0); - if(!monitor->currentRate.isEmpty()) - ui.rateCombo->setCurrentIndex(ui.rateCombo->findText(monitor->currentRate)); - else - ui.rateCombo->setCurrentIndex(0); - - // Set gamma values - ui.redSpinBox->setSingleStep(0.01); - ui.greenSpinBox->setSingleStep(0.01); - ui.blueSpinBox->setSingleStep(0.01); - if(!monitor->gamma.isEmpty()) { - QStringList gammaValues = monitor->gamma.split(":"); - ui.redSpinBox->setValue(gammaValues[0].toFloat()); - ui.greenSpinBox->setValue(gammaValues[1].toFloat()); - ui.blueSpinBox->setValue(gammaValues[2].toFloat()); - } + +QString modeToString(KScreen::ModePtr mode) { + // mode->name() can be anything, not just widthxheight. eg if added with cvt. + return QString("%1x%2").arg(mode->size().width()).arg(mode->size().height()); } -void MonitorWidget::onResolutionChanged(int index) { - QComboBox* combo =ui.resolutionCombo; - QComboBox* rateCombo = ui.rateCombo; - QString mode = combo->currentText(); - rateCombo->clear(); - rateCombo->addItem(tr("Auto")); - if( monitorInfo->monitorModes.contains(mode)) { - QStringList mode_lines = combo->currentData().value()->modeLines; - //QStringList mode_lines = monitorInfo->monitorModes[mode]->modeLines; - Q_FOREACH(QString rate, mode_lines) { - rateCombo->addItem(rate); +MonitorWidget::MonitorWidget(KScreen::OutputPtr output, KScreen::ConfigPtr config, QWidget* parent): + QGroupBox(parent) +{ + this->output = output; + + ui.setupUi(this); + + ui.xPosSpinBox->setValue(output->pos().x()); + ui.yPosSpinBox->setValue(output->pos().y()); + + ui.enabledCheckbox->setChecked(output->isEnabled()); + ui.isPrimaryCheckbox->setChecked(output->isPrimary()); + + // Add the preferred mode at the top of the list + KScreen::ModePtr preferredMode = output->preferredMode(); + if (preferredMode) { + ui.resolutionCombo->addItem(modeToString(preferredMode), preferredMode->id()); + // Make it bold, for good measure + QFont font = ui.resolutionCombo->font(); + font.setBold(true); + ui.resolutionCombo->setItemData(0, font, Qt::FontRole); } - rateCombo->setCurrentIndex(0); - } -} + // Add each mode to the list + Q_FOREACH(const KScreen::ModePtr &mode, output->modes()) { + // TODO better check for duplicates + if (mode == preferredMode) continue; + ui.resolutionCombo->addItem(modeToString(mode), mode->id()); + } + connect(ui.resolutionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onResolutionChanged(int))); -void MonitorWidget::disablePositionOption(bool disable) { - bool enable = !disable; - ui.xPosSpinBox->setEnabled(enable); - ui.yPosSpinBox->setEnabled(enable); - ui.xPosLabel->setEnabled(enable); - ui.yPosLabel->setEnabled(enable); - ui.positionLabel->setEnabled(enable); + if (output->currentMode()) { + // Set the current mode in dropdown + int idx = ui.resolutionCombo->findData(output->currentMode()->id()); + ui.resolutionCombo->setCurrentIndex(idx); + } + updateRefreshRates(); + + /* XXX setting gamma not possible yet + KScreen::Edid* edid = output->edid(); + if (edid && edid->isValid()) {}*/ + + if (config->connectedOutputs().count() == 1) { + setOnlyMonitor(true); + } else { + Q_FOREACH(KScreen::OutputPtr clone, config->connectedOutputs()) { + // We can't clone ourselves, or an output that already clones another + if (clone == output || clone->clones().count()) continue; + ui.clonesCombo->addItem(clone->name(), clone->id()); + } + } } -MonitorSettings* MonitorWidget::getSettings() { - MonitorSettings* s = new MonitorSettings(); - s->name = monitorInfo->name; - s->enabledOk = ui.enabled->isChecked(); - s->currentMode = ui.resolutionCombo->currentText(); - s->currentRate = ui.rateCombo->currentText(); - if( ! ui.xPosSpinBox->isEnabled() ) { // If no unify monitor is selected, then position is disabled. - s->position = MonitorSettings::None; - } else { - s->position = MonitorSettings::Manual; - } - s->xPos=ui.xPosSpinBox->value(); - s->yPos=ui.yPosSpinBox->value(); - s->gamma = QString("%1:%2:%3").arg(ui.redSpinBox->value()).arg(ui.greenSpinBox->value()).arg(ui.blueSpinBox->value()); - return s; +void MonitorWidget::onResolutionChanged(int index) { + qDebug() << "Set id to" << ui.resolutionCombo->currentData(); + + updateRefreshRates(); + // TODO enable Apply button } -void MonitorWidget::chooseMaxResolution() { - if(ui.resolutionCombo->count() > 1) - ui.resolutionCombo->setCurrentIndex(1); + +void MonitorWidget::updateRefreshRates() { + ui.rateCombo->clear(); + KScreen::ModePtr selectedMode = output->currentMode(); // XXX That's wrong + Q_FOREACH(const KScreen::ModePtr &mode, output->modes()) { + if (mode->size() == selectedMode->size()) { + ui.rateCombo->addItem(tr("%1 Hz").arg(mode->refreshRate()), mode->id()); + } + } } -void MonitorWidget::enableMonitor(bool enable) { - ui.enabled->setChecked(enable); + +void MonitorWidget::setOnlyMonitor(bool isOnlyMonitor) { + qDebug() << "set only monitor" << isOnlyMonitor; + ui.xPosSpinBox->setVisible(!isOnlyMonitor); + ui.yPosSpinBox->setVisible(!isOnlyMonitor); + ui.xPosLabel->setVisible(!isOnlyMonitor); + ui.yPosLabel->setVisible(!isOnlyMonitor); + ui.extendsRadio->setVisible(!isOnlyMonitor); + ui.clonesRadio->setVisible(!isOnlyMonitor); + ui.clonesCombo->setVisible(!isOnlyMonitor); + ui.enabledCheckbox->setEnabled(!isOnlyMonitor); + ui.enabledCheckbox->setEnabled(!isOnlyMonitor); } diff --git a/lxqt-config-monitor/monitorwidget.h b/lxqt-config-monitor/monitorwidget.h index 12a09e68d..96804f567 100644 --- a/lxqt-config-monitor/monitorwidget.h +++ b/lxqt-config-monitor/monitorwidget.h @@ -25,29 +25,28 @@ #include #include #include +#include + #include "ui_monitorwidget.h" -class MonitorInfo; -class MonitorSettings; // Monitor info class MonitorWidget : public QGroupBox { Q_OBJECT public: - MonitorWidget(MonitorInfo* monitor, const QList< MonitorInfo* > monitorsInfo, QWidget* parent = 0); - MonitorSettings* getSettings(); - void chooseMaxResolution(); - void enableMonitor(bool enable); + MonitorWidget(KScreen::OutputPtr output, KScreen::ConfigPtr config, QWidget* parent = 0); + + void updateRefreshRates(); - MonitorInfo* monitorInfo; + KScreen::OutputPtr output; - Ui::MonitorWidget ui; + Ui::MonitorWidget ui; public Q_SLOTS: - void disablePositionOption(bool disabled); + void setOnlyMonitor(bool isOnlyMonitor); private Q_SLOTS: - void onResolutionChanged(int); + void onResolutionChanged(int); }; #endif // _MONITORWIDGET_H_ diff --git a/lxqt-config-monitor/monitorwidget.ui b/lxqt-config-monitor/monitorwidget.ui index 1c8ba6d1a..29982f3ce 100644 --- a/lxqt-config-monitor/monitorwidget.ui +++ b/lxqt-config-monitor/monitorwidget.ui @@ -6,169 +6,213 @@ 0 0 - 349 - 286 + 335 + 382 - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Turn on + + + + + 0 - - - - - - Resolution: - - - - - - - - - - Rate: - - - - - - - - - - - - - 0 - 0 - - - - Hz - - - - - - - - - Position: - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - x: - + + + Screen setup + + + + + + Enable this display + + + + + + + 24 + + + + + Make this the primary display + + + + + + + + + + + Resolution: + + + + + + + + + + + + This screen extends the desktop + + + true + + + buttonGroup + + + + + + + + + x: + + + + + + + -10000000 + + + 10000000 + + + + + + + y: + + + + + + + -10000000 + + + 10000000 + + + + + + + + + This screen clones another screen + + + buttonGroup + + + + + + + + extendsRadio + clonesRadio + clonesCombo + enabledCheckbox + + + + Advanced settings + + + + + 110 + 30 + 81 + 31 + + + + + None + + + + + Left + + + + + Inverted + + + + + Right + + - - - - - -10000000 + + + + 28 + 30 + 76 + 31 + - - 10000000 - - - - - - y: - - - - - - - -10000000 - - - 10000000 + Rotation: - - - - - - - Gamma: - - - - - - - - - 10.000000000000000 + + + + 110 + 80 + 111 + 32 + - - 1.000000000000000 - - - - - - - : + + + 0 + 0 + - - - - - 10.000000000000000 - - - 1.000000000000000 + + + + 20 + 80 + 91 + 31 + - - - - - : + Refresh rate: - - - - - 10.000000000000000 - - - 1.000000000000000 - - - 1.000000000000000 - - - - + + + + + diff --git a/lxqt-config-monitor/xrandr.h b/lxqt-config-monitor/xrandr.h deleted file mode 100644 index 7861abaf6..000000000 --- a/lxqt-config-monitor/xrandr.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (C) 2014 P.L. Lucas - - 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 Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef _XRANDR_H_ -#define _XRANDR_H_ - -#include "monitor.h" -#include - - -class XRandRBackend: public MonitorSettingsBackend { - Q_OBJECT -public: - // Execute xrandr command and read its output - QList getMonitorsInfo(); - // Set changes in xrandr - bool setMonitorsSettings(const QList monitors); - QString getCommand(const QList monitors); -}; - -#endif \ No newline at end of file