Commit e40ddbd5 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Use PlasmaComponents.Dialog for ModeSelectionWidget

PlasmaCore.Dialog was eating mouse clicks for some reason, but
wrapping the ModeSelectionWidget to PlasmaComponents.Dialog works.
And it looks better.

BUG: 312544
parent 2c69270f
set(QML_FILES
main.qml
IconButton.qml
ModeSelectionDialog.qml
OutputView.qml
Output.qml
OutputIdentifier.qml
......
/*
Copyright (C) 2012 Dan Vratil <dvratil@redhat.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 1.1
import org.kde.plasma.components 0.1 as PlasmaComponents;
import org.kde.plasma.core 0.1 as PlasmaCore
import KScreen 1.0
PlasmaCore.Dialog {
id: dialog;
property Item parentItem;
property Item visualParent;
property int status: PlasmaComponents.DialogStatus.Closed;
visible: false;
windowFlags: Qt.Popup;
onVisibleChanged: {
if (visible) {
status = PlasmaComponents.DialogStatus.Open;
} else {
status = PlasmaComponents.DialogStatus.Closed;
}
}
mainItem: ModeSelectionWidget {
id: contentItem;
output: parentItem;
width: 300;
}
function open() {
var parent = dialog.visualParent ? dialog.visualParent : dialog.parent;
var pos = dialog.popupPosition(parent, Qt.alignCenter);
dialog.x = pos.x;
dialog.y = pos.y;
dialog.visible = true;
dialog.activateWindow();
}
function close() {
dialog.visible = false;
}
}
......@@ -280,11 +280,20 @@ Item {
}
]
ModeSelectionDialog {
PlasmaComponents.Dialog {
id: selectionDialog;
id: selectionDialog;
visualParent: resizeButton;
content: [
ModeSelectionWidget {
id: contentItem;
output: root.parentItem;
onAccepted: selectionDialog.close();
}
]
parentItem: parent.parentItem;
visualParent: resizeButton;
}
}
......@@ -20,37 +20,53 @@
#include <QListView>
#include <QGridLayout>
#include <QPainter>
#include <QGraphicsProxyWidget>
#include <kscreen/output.h>
#include <KDebug>
#include <QRectF>
#include <sys/socket.h>
#include "qmloutput.h"
#include "modesproxymodel.h"
#include "resolutionsortmodel.h"
ModeSelectionWidget::ModeSelectionWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags):
QGraphicsProxyWidget(parent, wFlags),
m_output(0)
ModeSelectionWidget::ModeSelectionWidget(QDeclarativeItem *parent):
QDeclarativeItem(parent),
m_output(0),
m_refreshRatesModel(new ModesProxyModel(this)),
m_resolutionsModel(new ResolutionSortModel(this))
{
m_resolutionsModel = new ResolutionSortModel(this);
setFlag(QGraphicsItem::ItemHasNoContents, false);
m_resolutionsView = new QListView();
rootWidget = new QWidget();
m_resolutionsView = new QListView(rootWidget);
m_resolutionsView->setModel(m_resolutionsModel);
m_resolutionsView->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(m_resolutionsView, SIGNAL(clicked(QModelIndex)), SLOT(resolutionChanged(QModelIndex)));
connect(m_resolutionsView, SIGNAL(doubleClicked(QModelIndex)), SLOT(acceptMode(QModelIndex)));
m_refreshRatesModel = new ModesProxyModel(this);
m_refreshRatesView = new QListView();
m_refreshRatesView = new QListView(rootWidget);
m_refreshRatesView->setModel(m_refreshRatesModel);
connect(m_resolutionsView, SIGNAL(clicked(QModelIndex)), SLOT(refreshRateChanged()));
QWidget *rootWidget = new QWidget();
m_refreshRatesView->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(m_refreshRatesView, SIGNAL(clicked(QModelIndex)), SLOT(refreshRateChanged()));
connect(m_refreshRatesView, SIGNAL(doubleClicked(QModelIndex)), SLOT(acceptMode(QModelIndex)));
QGridLayout *mainLayout = new QGridLayout(rootWidget);
mainLayout->addWidget(m_resolutionsView, 0, 0);
mainLayout->addWidget(m_refreshRatesView, 0, 1);
rootWidget->setLayout(mainLayout);
rootWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
rootWidget->setMaximumSize(300, 250);
rootWidget->setAttribute(Qt::WA_OpaquePaintEvent);
m_proxyWidget = new QGraphicsProxyWidget(this);
m_proxyWidget->setWidget(rootWidget);
setWidget(rootWidget);
/* FIXME: Shouldn't this be automatic? */
setWidth(m_proxyWidget->geometry().width());
setHeight(m_proxyWidget->geometry().height());
}
ModeSelectionWidget::~ModeSelectionWidget()
......@@ -104,6 +120,22 @@ void ModeSelectionWidget::resolutionChanged(const QModelIndex &index)
}
}
void ModeSelectionWidget::acceptMode(const QModelIndex &index)
{
if (!index.isValid()) {
return;
}
if (sender() == m_refreshRatesView) {
refreshRateChanged();
Q_EMIT accepted();
} else if (sender() == m_resolutionsView) {
resolutionChanged(index);
Q_EMIT accepted();
}
}
void ModeSelectionWidget::refreshRateChanged()
{
if (!m_output) {
......
......@@ -19,7 +19,7 @@
#ifndef MODESELECTIONWIDGET_H
#define MODESELECTIONWIDGET_H
#include <QGraphicsProxyWidget>
#include <QDeclarativeItem>
#include <QModelIndex>
class QListView;
......@@ -27,12 +27,12 @@ class QMLOutput;
class ModesProxyModel;
class ResolutionSortModel;
class ModeSelectionWidget : public QGraphicsProxyWidget
class ModeSelectionWidget : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(QMLOutput *output READ output WRITE setOutput)
public:
explicit ModeSelectionWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
explicit ModeSelectionWidget(QDeclarativeItem *parent = 0);
virtual ~ModeSelectionWidget();
void setOutput(QMLOutput *output);
......@@ -40,8 +40,12 @@ public:
private Q_SLOTS:
void resolutionChanged(const QModelIndex &index);
void acceptMode(const QModelIndex &index);
void refreshRateChanged();
Q_SIGNALS:
void accepted();
private:
QMLOutput *m_output;
......@@ -49,6 +53,9 @@ private:
QListView *m_refreshRatesView;
ModesProxyModel *m_refreshRatesModel;
ResolutionSortModel *m_resolutionsModel;
QWidget *rootWidget;
QGraphicsProxyWidget *m_proxyWidget;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment