[harmattan] added a MyTheme object that behaves similar to the sailfish Theme object (a name which sadly is reserved and can not be used in QML :( )

This commit is contained in:
Hauke Schade 2014-04-04 21:54:41 +02:00
parent 4ee23ebfd9
commit 7c4d8905c6
20 changed files with 160 additions and 71 deletions

View file

@ -32,6 +32,11 @@
#include "qmlutils.hh"
#include "mynetworkmanager.hh"
#if defined(Q_OS_SAILFISH)
#else
#include "theme.hh"
#endif
Q_DECL_EXPORT int main(int argc, char *argv[])
{
#if defined(Q_OS_SAILFISH)
@ -74,6 +79,11 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
viewer->rootContext()->setContextProperty("QMLUtils", QMLUtils::instance());
viewer->rootContext()->setContextProperty("settings", Settings::instance());
#if defined(Q_OS_SAILFISH)
#else
viewer->rootContext()->setContextProperty("MyTheme", Theme::instance());
#endif
#if defined(Q_OS_SAILFISH)
viewer->setSource(SailfishApp::pathTo("qml/sailfish/harbour-ttrss.qml"));
#else

View file

@ -20,8 +20,8 @@ Item {
property color color: constant.colorListItemActive
implicitWidth: internal.getBubbleWidth()
implicitHeight: root.large ? constant.fontSizeSmall + constant.paddingMedium + constant.paddingMedium :
constant.fontSizeXSmall + constant.paddingMedium + constant.paddingMedium
implicitHeight: root.large ? MyTheme.fontSizeSmall + MyTheme.paddingMedium + MyTheme.paddingMedium :
MyTheme.fontSizeExtraSmall + MyTheme.paddingMedium + MyTheme.paddingMedium
BorderImage {
source: "image://theme/meegotouch-countbubble-background"
@ -41,7 +41,7 @@ Item {
opacity: 0.8
anchors.horizontalCenter: parent.horizontalCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: root.large ? constant.fontSizeMedium : constant.fontSizeXSmall
font.pixelSize: root.large ? MyTheme.fontSizeMedium : MyTheme.fontSizeExtraSmall
color: root.color
text: root.amount
@ -52,9 +52,9 @@ Item {
function getBubbleWidth() {
if (large)
return text.paintedWidth + constant.paddingLarge + constant.paddingLarge
return text.paintedWidth + MyTheme.paddingMedium + MyTheme.paddingMedium
else
return text.paintedWidth + constant.paddingSmall + constant.paddingSmall
return text.paintedWidth + MyTheme.paddingSmall + MyTheme.paddingSmall
}
}
}

View file

@ -31,7 +31,7 @@ Dialog {
width: parent.width
Text {
id: errorDialogText
font.pixelSize: constant.fontSizeSmall
font.pixelSize: MyTheme.fontSizeSmall
anchors.centerIn: parent
color: "white"
text: errorDialog.text

View file

@ -49,7 +49,7 @@ Item{
verticalCenter: parent.verticalCenter
left: parent.left
// right: mainText.left
margins: constant.paddingLarge
margins: MyTheme.paddingLarge
}
}
@ -59,11 +59,11 @@ Item{
verticalCenter: parent.verticalCenter
left: logourl.length > 3 ? logo.right : parent.left
right: updateAction.left
margins: constant.paddingXLarge
margins: MyTheme.paddingLarge
}
Label {
id: mainText
font.pixelSize: constant.fontSizeXLarge
font.pixelSize: MyTheme.fontSizeLarge
color: "white"
elide: Text.ElideRight
maximumLineCount: 3
@ -81,7 +81,7 @@ Item{
}
Label {
id: subText
font.pixelSize: constant.fontSizeSmall
font.pixelSize: MyTheme.fontSizeSmall
color: "white"
elide: Text.ElideRight
maximumLineCount: 1
@ -94,7 +94,7 @@ Item{
id: updateAction
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: constant.paddingLarge
anchors.rightMargin: MyTheme.paddingLarge
width: updateIcon.width
height: updateIcon.height
visible: hasUpdateAction || network.loading

View file

@ -21,7 +21,7 @@ Item {
Image {
anchors.left: parent.left
anchors.right: sectionLabel.left
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingSmall
anchors.verticalCenter: parent.verticalCenter
source: "image://theme/meegotouch-groupheader"+(theme.inverted?"-inverted":"")+"-background"
@ -32,7 +32,7 @@ Item {
anchors.right: parent.right
color: constant.sectionLabel
font.pixelSize: constant.fontSizeXSmall
font.pixelSize: MyTheme.fontSizeTiny
font.weight: Font.Bold
text: section

View file

@ -22,7 +22,7 @@ Row {
width: parent.width
layoutDirection: Qt.RightToLeft
spacing: constant.paddingLarge
spacing: MyTheme.paddingMedium
Switch {
id: myswitch

View file

@ -15,6 +15,7 @@ import com.nokia.extras 1.1
Dialog {
id: popup
width: parent.width
property alias text: popupitem.text
@ -28,7 +29,7 @@ Dialog {
content: Text {
id: popupitem
width: parent.width
font.pixelSize: constant.fontSizeSmall
font.pixelSize: MyTheme.fontSizeSmall
anchors.centerIn: parent
color: "white"
textFormat: Text.RichText

View file

@ -23,7 +23,7 @@ Page {
bottom: parent.bottom
left: parent.left
right: parent.right
margins: constant.paddingLarge
margins: MyTheme.paddingMedium
}
ListView {
id: listView

View file

@ -27,8 +27,8 @@ Item {
id: background
anchors.fill: parent
// Fill page borders
anchors.leftMargin: -constant.paddingLarge
anchors.rightMargin: -constant.paddingLarge
anchors.leftMargin: -MyTheme.paddingMedium
anchors.rightMargin: -MyTheme.paddingMedium
visible: mouseArea.pressed
source: "image://theme/meegotouch-list-background-selected-center"
}
@ -37,19 +37,19 @@ Item {
id: mainText
text: model.title
anchors.right: unreadBubble.left
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingMedium
anchors.left: parent.left
anchors.leftMargin: 0
anchors.verticalCenter: parent.verticalCenter
font.weight: Font.Bold
font.pixelSize: constant.fontSizeLarge
font.pixelSize: MyTheme.fontSizeLarge
color: (model.unreadcount > 0) ? constant.colorListItemActive : constant.colorListItemDisabled
}
Bubble {
id: unreadBubble
anchors.right: drilldownarrow.left
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
amount: model.unreadcount

View file

@ -27,8 +27,8 @@ Item {
id: background
anchors.fill: parent
// Fill page borders
anchors.leftMargin: -constant.paddingLarge
anchors.rightMargin: -constant.paddingLarge
anchors.leftMargin: -MyTheme.paddingMedium
anchors.rightMargin: -MyTheme.paddingMedium
visible: mouseArea.pressed
source: "image://theme/meegotouch-list-background-selected-center"
}
@ -42,7 +42,7 @@ Item {
height:60
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingMedium
source: model.icon
onStatusChanged: {
@ -57,19 +57,19 @@ Item {
id: mainText
text: model.title
anchors.right: unreadBubble.left
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingMedium
anchors.left: icon.visible ? icon.right : parent.left
anchors.leftMargin: constant.listItemSpacing
anchors.leftMargin: MyTheme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
font.weight: Font.Bold
font.pixelSize: constant.fontSizeLarge
font.pixelSize: MyTheme.fontSizeLarge
color: (model.unreadcount > 0) ? constant.colorListItemActive : constant.colorListItemDisabled
}
Bubble {
id: unreadBubble
anchors.right: drilldownarrow.left
anchors.rightMargin: constant.listItemSpacing
anchors.rightMargin: MyTheme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
amount: model.unreadcount

View file

@ -49,7 +49,7 @@ Page {
id: content
Row {
id: labelsrepeater
spacing: constant.paddingMedium
spacing: MyTheme.paddingMedium
Repeater {
model: root.labels
LabelLabel {

View file

@ -19,23 +19,23 @@ Item {
signal pressAndHold
property alias pressed: mouseArea.pressed
height: mainText.parent.height + constant.paddingLarge
height: mainText.parent.height + MyTheme.paddingMedium
width: parent.width
BorderImage {
id: background
anchors.fill: parent
// Fill page borders
anchors.leftMargin: -constant.paddingLarge
anchors.rightMargin: -constant.paddingLarge
anchors.leftMargin: -MyTheme.paddingMedium
anchors.rightMargin: -MyTheme.paddingMedium
visible: mouseArea.pressed
source: "image://theme/meegotouch-list-background-selected-center"
}
Row {
spacing: constant.paddingMedium
spacing: MyTheme.paddingMedium
anchors.fill: parent
anchors.leftMargin: icon.visible ? icon.width + constant.listItemSpacing : 0
anchors.leftMargin: icon.visible ? icon.width + MyTheme.paddingMedium : 0
Image {
source: "../resources/ic_star_enabled.png"
visible: model.marked
@ -53,7 +53,7 @@ Item {
Row {
anchors.left: parent.left
anchors.right: drilldownarrow.left
spacing: constant.listItemSpacing
spacing: MyTheme.paddingMedium
clip: true
Image {
@ -80,7 +80,7 @@ Item {
id: mainText
text: model.title
font.weight: Font.Bold
font.pixelSize: constant.fontSizeLarge
font.pixelSize: MyTheme.fontSizeLarge
color: (model.unread > 0) ? constant.colorListItemActive : constant.colorListItemDisabled;
elide: Text.ElideRight
}
@ -89,7 +89,7 @@ Item {
id: subText
text: model.subtitle
font.weight: Font.Light
font.pixelSize: constant.fontSizeSmall
font.pixelSize: MyTheme.fontSizeSmall
color: (model.unread > 0) ? constant.colorListItemActiveTwo : constant.colorListItemDisabled;
elide: Text.ElideRight
visible: text != ""
@ -97,7 +97,7 @@ Item {
Row {
id: myrow
property variant mymod: model
spacing: constant.paddingMedium
spacing: MyTheme.paddingSmall
Repeater {
model: myrow.mymod.labels

View file

@ -36,7 +36,7 @@ Page {
ListView {
id: listView
anchors.fill: parent
anchors.margins: constant.paddingLarge
anchors.margins: MyTheme.paddingMedium
model: feedItems
@ -80,7 +80,7 @@ Page {
qsTr("Loading") :
rootWindow.showAll ? qsTr("No items in feed") : qsTr("No unread items in feed")
anchors.fill: parent
anchors.margins: constant.paddingLarge
anchors.margins: MyTheme.paddingLarge
visible: feedItems.count == 0
}
}

View file

@ -30,7 +30,7 @@ Page {
bottom: parent.bottom
left: parent.left
right: parent.right
margins: constant.paddingLarge
margins: MyTheme.paddingMedium
}
ListView {
id: listView
@ -115,8 +115,8 @@ Page {
content: Flickable {
anchors.fill: parent
anchors.leftMargin: 10
anchors.topMargin: 10
anchors.leftMargin: MyTheme.paddingMedium
anchors.topMargin: MyTheme.paddingMedium
flickableDirection: Flickable.VerticalFlick
Column {
id: col2
@ -127,7 +127,7 @@ Page {
id: serverLabel
text: qsTr("Feed address:")
width: parent.width
font.pixelSize: constant.fontSizeMedium
font.pixelSize: MyTheme.fontSizeMedium
}
TextField {
id: server

View file

@ -17,11 +17,11 @@ Rectangle {
id: root
property variant label
width: text.width + constant.paddingSmall + constant.paddingSmall
height: text.height + constant.paddingSmall
width: text.width + MyTheme.paddingSmall + MyTheme.paddingSmall
height: text.height + MyTheme.paddingSmall
color: root.label.bgcolor
radius: constant.paddingSmall
anchors.margins: constant.paddingSmall
radius: MyTheme.paddingSmall
anchors.margins: MyTheme.paddingSmall
Text {
anchors {
verticalCenter: root.verticalCenter
@ -30,7 +30,7 @@ Rectangle {
id: text
text: root.label.text
color: root.label.fgcolor
font.pixelSize: constant.fontSizeXSmall
font.pixelSize: MyTheme.fontSizeExtraSmall
}
MouseArea {
id: touchArea

View file

@ -34,14 +34,14 @@ Page {
id: settingsColumn
anchors {
top: pageHeader.bottom
topMargin: constant.paddingLarge
topMargin: MyTheme.paddingMedium
left: parent.left
leftMargin: constant.paddingLarge
leftMargin: MyTheme.paddingMedium
right: parent.right
rightMargin: constant.paddingLarge
rightMargin: MyTheme.paddingMedium
}
height: childrenRect.height
spacing: constant.paddingXLarge
spacing: MyTheme.paddingMedium
SettingsButtonRow {
text: qsTr("Theme")

View file

@ -26,22 +26,6 @@ QtObject{
property color colorFastScrollText: theme.inverted ? "#000033" : "#8c8c8c"
property int listItemSpacing: 10
property int paddingSmall: 4
property int paddingMedium: 6
property int paddingLarge: 8
property int paddingXLarge: 12
property int paddingXXLarge: 16
property int fontSizeXXSmall: 16
property int fontSizeXSmall: 20
property int fontSizeSmall: 22
property int fontSizeMedium: 24
property int fontSizeLarge: 26
property int fontSizeXLarge: 28
property int fontSizeXXLarge: 32
property int headerHeight: inPortrait ? 72 : 56
property int headerLogoHeight: inPortrait ? 56 : 40

45
theme.cpp Normal file
View file

@ -0,0 +1,45 @@
//Copyright Hauke Schade, 2012-2013
//
//This file is part of TTRss.
//
//TTRss 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.
//TTRss 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 TTRss (on a Maemo/Meego system there is a copy
//in /usr/share/common-licenses. If not, see http://www.gnu.org/licenses/.
#include "theme.hh"
QScopedPointer<Theme> Theme::m_instance(0);
Theme *Theme::instance() {
if (m_instance.isNull())
m_instance.reset(new Theme);
return m_instance.data();
}
Theme::Theme(QObject *parent) : QObject(parent) { }
int Theme::fontSizeTiny() const {
return 18; }
int Theme::fontSizeExtraSmall() const {
return 20; }
int Theme::fontSizeSmall() const {
return 22; }
int Theme::fontSizeMedium() const {
return 24; }
int Theme::fontSizeLarge() const {
return 26; }
int Theme::fontSizeExtraLarge() const {
return 30; }
int Theme::fontSizeHuge() const {
return 34; }
int Theme::paddingSmall() const {
return 6; }
int Theme::paddingMedium() const {
return 8; }
int Theme::paddingLarge() const {
return 10; }

47
theme.hh Normal file
View file

@ -0,0 +1,47 @@
#ifndef THEME_HH
#define THEME_HH
#include <QtCore/QObject>
class Theme : public QObject
{
Q_OBJECT
Q_PROPERTY(int fontSizeTiny READ fontSizeTiny NOTIFY themeChanged)
Q_PROPERTY(int fontSizeExtraSmall READ fontSizeExtraSmall NOTIFY themeChanged)
Q_PROPERTY(int fontSizeSmall READ fontSizeSmall NOTIFY themeChanged)
Q_PROPERTY(int fontSizeMedium READ fontSizeMedium NOTIFY themeChanged)
Q_PROPERTY(int fontSizeLarge READ fontSizeLarge NOTIFY themeChanged)
Q_PROPERTY(int fontSizeExtraLarge READ fontSizeExtraLarge NOTIFY themeChanged)
Q_PROPERTY(int fontSizeHuge READ fontSizeHuge NOTIFY themeChanged)
Q_PROPERTY(int paddingSmall READ paddingSmall NOTIFY themeChanged)
Q_PROPERTY(int paddingMedium READ paddingMedium NOTIFY themeChanged)
Q_PROPERTY(int paddingLarge READ paddingLarge NOTIFY themeChanged)
public:
static Theme *instance();
int fontSizeTiny() const;
int fontSizeExtraSmall() const;
int fontSizeSmall() const;
int fontSizeMedium() const;
int fontSizeLarge() const;
int fontSizeExtraLarge() const;
int fontSizeHuge() const;
int paddingSmall() const;
int paddingMedium() const;
int paddingLarge() const;
signals:
void themeChanged();
private:
static QScopedPointer<Theme> m_instance;
explicit Theme(QObject *parent = 0);
Q_DISABLE_COPY(Theme)
};
#endif // THEME_HH

View file

@ -48,7 +48,8 @@ contains(MEEGO_EDITION,harmattan) {
SOURCES += main.cpp \
settings.cpp \
mynetworkmanager.cpp \
qmlutils.cpp
qmlutils.cpp \
theme.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
@ -60,7 +61,8 @@ RESOURCES += \
HEADERS += \
settings.hh \
mynetworkmanager.hh \
qmlutils.hh
qmlutils.hh \
theme.hh
OTHER_FILES += \
qtc_packaging/debian_harmattan/rules \