get rid of hardcoded qml ui elements

REVIEW: 105018
CCBUG: 291612
This commit is contained in:
Thomas Lübking 2012-05-22 19:32:53 +02:00
parent 6cde471ec8
commit 52caeffe22
13 changed files with 104 additions and 246 deletions

View file

@ -30,5 +30,4 @@ install(TARGETS kcm_kwindecoration DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES kwindecoration.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install( FILES qml/main.qml qml/AuroraeDecoration.qml qml/AuroraePreview.qml qml/OxygenScrollbar.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/kcm_kwindecoration)
install( DIRECTORY qml/images/ DESTINATION ${DATA_INSTALL_DIR}/kwin/kcm_kwindecoration/images)
install( FILES qml/main.qml qml/AuroraeDecoration.qml qml/AuroraePreview.qml DESTINATION ${DATA_INSTALL_DIR}/kwin/kcm_kwindecoration)

View file

@ -7,10 +7,10 @@
<x>0</x>
<y>0</y>
<width>681</width>
<height>515</height>
<height>595</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,100,1">
<item>
<widget class="KLineEdit" name="searchEdit">
<property name="clickMessage">
@ -26,6 +26,15 @@
<property name="whatsThis">
<string>Select the window decoration. This is the look and feel of both the window borders and the window handle.</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
</widget>
</item>
<item>
@ -70,15 +79,20 @@
</widget>
<customwidgets>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
<class>QDeclarativeView</class>
<extends>QGraphicsView</extends>
<header>QtDeclarative/QDeclarativeView</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>searchEdit</tabstop>

View file

@ -34,12 +34,15 @@
#include "decorationmodel.h"
#include "auroraetheme.h"
// Qt
#include <QTimer>
#include <QtDBus/QtDBus>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeView>
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QGraphicsObject>
#include <QtGui/QScrollBar>
// KDE
#include <KAboutData>
#include <KDialog>
@ -89,10 +92,6 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &
m_proxyModel->setSourceModel(m_model);
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_ui->decorationList->setResizeMode(QDeclarativeView::SizeRootObjectToView);
m_ui->decorationList->setAttribute(Qt::WA_TranslucentBackground);
QPalette pal = m_ui->decorationList->palette();
pal.setColor(m_ui->decorationList->backgroundRole(), Qt::transparent);
m_ui->decorationList->setPalette(pal);
foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) {
m_ui->decorationList->engine()->addImportPath(importPath);
}
@ -106,11 +105,20 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &
connect(m_ui->decorationList->rootObject(), SIGNAL(currentIndexChanged()), SLOT(slotSelectionChanged()));
connect(m_ui->decorationList->rootObject(), SIGNAL(widthChanged()), m_model, SLOT(regeneratePreviews()));
connect(m_ui->decorationList->rootObject(), SIGNAL(contentYChanged()), SLOT(updateScrollbarValue()));
connect(m_ui->decorationList->rootObject(), SIGNAL(contentHeightChanged()), SLOT(updateScrollbarRange()));
connect(m_ui->configureButtonsButton, SIGNAL(clicked(bool)), this, SLOT(slotConfigureButtons()));
connect(m_ui->ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNSClicked()));
connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), m_proxyModel, SLOT(setFilterFixedString(QString)));
connect(m_ui->configureDecorationButton, SIGNAL(clicked(bool)), SLOT(slotConfigureDecoration()));
m_ui->decorationList->disconnect(m_ui->decorationList->verticalScrollBar());
m_ui->decorationList->verticalScrollBar()->disconnect(m_ui->decorationList);
connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(rangeChanged(int, int )), SLOT(updateScrollbarRange()));
connect(m_ui->decorationList->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(updateViewPosition(int)));
m_ui->decorationList->installEventFilter(this);
KAboutData *about =
new KAboutData(I18N_NOOP("kcmkwindecoration"), 0,
ki18n("Window Decoration Control Module"),
@ -119,6 +127,7 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &
about->addAuthor(ki18n("Karol Szwed"), KLocalizedString(), "gallium@kde.org");
setAboutData(about);
m_model->regeneratePreviews();
QMetaObject::invokeMethod(this, "setSliderWidth", Qt::QueuedConnection);
}
@ -349,6 +358,40 @@ void KWinDecorationModule::slotConfigureDecoration()
}
}
bool KWinDecorationModule::eventFilter(QObject *o, QEvent *e)
{
if (o == m_ui->decorationList && e->type() == QEvent::Resize)
updateScrollbarRange();
return KCModule::eventFilter(o, e);
}
void KWinDecorationModule::setSliderWidth()
{
m_ui->decorationList->rootContext()->setContextProperty("sliderWidth", m_ui->decorationList->verticalScrollBar()->width());
}
void KWinDecorationModule::updateScrollbarRange()
{
m_ui->decorationList->verticalScrollBar()->blockSignals(true);
const int h = m_ui->decorationList->rootObject()->property("contentHeight").toInt();
m_ui->decorationList->verticalScrollBar()->setRange(0, h - m_ui->decorationList->height());
m_ui->decorationList->verticalScrollBar()->setPageStep(m_ui->decorationList->verticalScrollBar()->maximum()/m_model->rowCount());
m_ui->decorationList->verticalScrollBar()->blockSignals(false);
}
void KWinDecorationModule::updateScrollbarValue()
{
const int v = m_ui->decorationList->rootObject()->property("contentY").toInt();
m_ui->decorationList->verticalScrollBar()->blockSignals(true); // skippig this will kill kinetic scrolling but the scrollwidth is too low
m_ui->decorationList->verticalScrollBar()->setValue(v);
m_ui->decorationList->verticalScrollBar()->blockSignals(false);
}
void KWinDecorationModule::updateViewPosition(int v)
{
QGraphicsObject *list = m_ui->decorationList->rootObject();
list->setProperty("contentY", v);
}
DecorationButtons::DecorationButtons(QObject *parent)
: QObject(parent)
, m_customPositions(false)

View file

@ -105,6 +105,9 @@ signals:
void pluginSave(KConfigGroup &conf);
void pluginDefaults();
protected:
bool eventFilter(QObject *o, QEvent *e);
protected slots:
// Allows us to turn "save" on
void slotSelectionChanged();
@ -115,7 +118,12 @@ protected slots:
private:
void readConfig(const KConfigGroup& conf);
void writeConfig(KConfigGroup &conf);
private slots:
void setSliderWidth();
void updateScrollbarRange();
void updateScrollbarValue();
void updateViewPosition(int v);
private:
KSharedConfigPtr kwinConfig;
KWinDecorationForm* m_ui;

View file

@ -1,158 +0,0 @@
/********************************************************************
Copyright (C) 2012 Nuno Pinheiro <nuno@oxygen-icons.org>
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, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 1.0
Item {
property variant list
property int itemHeight: 1
id: verticalScroolbar
width:19
height: parent.height-1
anchors.right: parent.right
anchors.rightMargin: 2
clip:true
Item {
id: scroolerArea
width: parent.width
height: parent.height-uparrow.height*2
y:uparrow.height
opacity: scroolerAreaOver.containsMouse? 1:list.moving?1:dragarea.containsMouse? 1:dragarea.pressed?1: 0.3
Behavior on opacity {
NumberAnimation { duration: 600 }
}
MouseArea {
id: scroolerAreaOver
anchors.bottomMargin:-uparrow.height
anchors.topMargin: -uparrow.height
anchors.fill: parent
hoverEnabled: true
}
BorderImage {
id: scroller
source: "images/scrool.png"
width:parent.width
height:Math.max (14,parent.height*list.height/list.contentHeight)
y:parent.height*list.contentY/list.contentHeight
border.left: 7; border.top: 7
border.right: 7; border.bottom: 8
opacity: 1
}
BorderImage {
id: scrolleractive
source: "images/scroolactive.png"
width:parent.width
height:Math.max (14,parent.height*list.height/list.contentHeight)
y:parent.height*list.contentY/list.contentHeight
border.left: 7; border.top: 7
border.right: 7; border.bottom: 8
opacity:scroolerAreaOver.containsMouse? 1:dragarea.containsMouse?1:dragarea.pressed?1:0.01
Behavior on opacity {
NumberAnimation { duration: 400 }
}
MouseArea{
id:dragarea
anchors.fill:parent
hoverEnabled: true
drag.target: scrolleractive
drag.axis: Drag.YAxis
drag.minimumY: 0
drag.maximumY: scroolerArea.height-scrolleractive.height
onPositionChanged: list.contentY=scrolleractive.y*list.contentHeight/(scroolerArea.height)
}
}
}
Item{
id:uparrow
width:parent.width
height: parent.width-4
Image{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source:"images/arrowup.png"
opacity:uparrowOver.containsMouse? 0:1
Behavior on opacity {
NumberAnimation { duration: 300 }
}
}
Image{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source:"images/arrowupactive.png"
opacity: uparrowOver.containsMouse? 1:0
Behavior on opacity {
NumberAnimation { duration: 300 }
}
}
MouseArea {
id: uparrowOver
anchors.fill: parent
hoverEnabled: true
onClicked: {
if (!list.atYBeginning) {
list.contentY -= itemHeight;
if (list.contentY < 0) {
list.contentY = 0;
}
}
}
}
}
Item{
id:downarrow
width:parent.width
height: parent.width-4
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
Image{
rotation: 180
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source:"images/arrowup.png"
opacity:downarrowOver.containsMouse? 0:1
Behavior on opacity {
NumberAnimation { duration: 300 }
}
}
Image{
rotation: 180
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source:"images/arrowupactive.png"
opacity: downarrowOver.containsMouse? 1:0
Behavior on opacity {
NumberAnimation { duration: 300 }
}
}
MouseArea {
id: downarrowOver
anchors.fill: parent
hoverEnabled: true
onClicked: {
if (!list.atYEnd) {
list.contentY += itemHeight;
}
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 882 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 B

View file

@ -18,85 +18,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 1.1
import org.kde.qtextracomponents 0.1 as QtExtra
BorderImage {
property alias currentIndex: listView.currentIndex
source: "images/bg.png"
border {
left: 4
top: 4
right: 4
bottom: 4
ListView {
id: listView
x: 0
y: 0
model: decorationModel
highlight: Rectangle {
width: listView.width - sliderWidth
height: 150
color: highlightColor
opacity: 0.5
}
MouseArea {
id: focusOver
anchors.fill: parent
hoverEnabled: true
}
ListView {
id: listView
x: 3
height: parent.height - 1 // -1 on the account of the last pixel being a glow pixel
width: parent.width - 6 - scrollbar.width
model: decorationModel
highlight: Rectangle {
width: listView.width
height: 150
color: highlightColor
opacity: 0.5
highlightMoveDuration: 250
boundsBehavior: Flickable.StopAtBounds
delegate: Item {
width: listView.width - sliderWidth
height: 150
QtExtra.QPixmapItem {
pixmap: preview
anchors.fill: parent
visible: type == 0
}
highlightMoveDuration: 250
boundsBehavior: Flickable.StopAtBounds
delegate: Item {
width: listView.width
height: 150
QtExtra.QPixmapItem {
pixmap: preview
anchors.fill: parent
visible: type == 0
}
Loader {
source: type == 1 ? "AuroraePreview.qml" : ""
anchors.fill: parent
}
MouseArea {
hoverEnabled: false
anchors.fill: parent
onClicked: {
listView.currentIndex = index;
}
}
Loader {
source: type == 1 ? "AuroraePreview.qml" : ""
anchors.fill: parent
}
}
OxygenScrollbar {
id: scrollbar
list: listView
itemHeight: 150
}
BorderImage {
id: shadow
source: "images/shadow.png"
anchors.fill:parent
border.left: 4; border.top: 4
border.right: 4; border.bottom: 5
opacity:focusOver.containsMouse? 0.01:1 //insert here a proper focus mechanism
Behavior on opacity {
NumberAnimation { duration: 300 }
}
}
BorderImage {
id: glow
source: "images/glow.png"
anchors.fill:parent
border.left: 4; border.top: 4
border.right: 4; border.bottom: 5
opacity:focusOver.containsMouse? 1:0 //insert here a proper focus mechanism
Behavior on opacity {
NumberAnimation { duration: 300 }
MouseArea {
hoverEnabled: false
anchors.fill: parent
onClicked: {
listView.currentIndex = index;
}
}
}
}