[app] Allow to fix orientation

This commit is contained in:
Slava Monich 2016-10-07 19:40:18 +03:00
parent 5be7de14ba
commit d8964ee8b1
10 changed files with 225 additions and 6 deletions

View file

@ -35,8 +35,16 @@ import harbour.books 1.0
ApplicationWindow {
id: window
allowedOrientations: Orientation.All
allowedOrientations: {
switch (globalSettings.orientation) {
default:
case BooksSettings.OrientationAny: return Orientation.All
case BooksSettings.OrientationPortrait: return Orientation.Portrait
case BooksSettings.OrientationLandscape: return Orientation.Landscape
}
}
// Application title
//% "Books"
readonly property string title: qsTrId("harbour-books-app-name")

View file

@ -104,7 +104,11 @@ SilicaFlickable {
console.log(_settingsComponent.errorString())
}
}
pageStack.push(_settingsComponent, {"title" : text })
pageStack.push(_settingsComponent, {
"title" : text,
"allowedOrientations": window.allowedOrientations,
"followOrientationChanges": true
})
}
}
MenuItem {

View file

@ -35,6 +35,7 @@ import org.nemomobile.configuration 1.0
Page {
id: page
property bool followOrientationChanges
property alias title: pageHeader.title
readonly property string rootPath: "/apps/" + appName() + "/"
@ -43,13 +44,24 @@ Page {
var parts = Qt.resolvedUrl("dummy").split('/')
if (parts.length > 2) {
var name = parts[parts.length-3]
if (name.indexOf("swissclock") >= 0) {
if (name.indexOf("-books") >= 0) {
return name
}
}
return "harbour-books"
}
Loader {
active: followOrientationChanges
Connections {
target: orientation
onValueChanged: allowedOrientations =
(orientation.value === 1) ? Orientation.Portrait :
(orientation.value === 2) ? Orientation.Landscape :
Orientation.All
}
}
SilicaFlickable {
anchors.fill: parent
contentHeight: content.height
@ -89,6 +101,64 @@ Page {
onValueChanged: fontSizeSlider.value = value
}
}
ComboBox {
id: orientationComboBox
//: Combo box label
//% "Orientation"
label: qsTrId("harbour-books-settings-page-orientation_label")
value: currentItem ? currentItem.text : ""
property bool ready
menu: ContextMenu {
id: orientationMenu
readonly property int defaultIndex: 0
MenuItem {
//: Combo box value for dynamic orientation
//% "Dynamic"
text: qsTrId("harbour-books-settings-page-orientation-dynamic")
readonly property int value: 0
}
MenuItem {
//: Combo box value for portrait orientation
//% "Portrait"
text: qsTrId("harbour-books-settings-page-orientation-portrait")
readonly property int value: 1
}
MenuItem {
//: Combo box value for landscape orientation
//% "Landscape"
text: qsTrId("harbour-books-settings-page-orientation-landscape")
readonly property int value: 2
}
}
onCurrentItemChanged: {
if (ready && currentItem) {
orientation.value = currentItem.value
}
}
Component.onCompleted: {
orientation.updateControls()
ready = true
}
ConfigurationValue {
id: orientation
key: rootPath + "orientation"
defaultValue: 0
onValueChanged: updateControls()
function updateControls() {
var n = orientationMenu.children.length
var index = orientationMenu.defaultIndex
for (var i=0; i<n; i++) {
if (orientationMenu.children[i].value === value) {
index = i
break
}
}
orientationComboBox.currentIndex = index
}
}
}
}
}
}

View file

@ -47,11 +47,13 @@
#define KEY_CURRENT_BOOK "currentBook"
#define KEY_CURRENT_FOLDER "currentFolder"
#define KEY_INVERT_COLORS "invertColors"
#define KEY_ORIENTATION "orientation"
#define DEFAULT_FONT_SIZE 0
#define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_CURRENT_FOLDER QString()
#define DEFAULT_INVERT_COLORS false
#define DEFAULT_ORIENTATION (BooksSettings::OrientationAny)
#define PAGETOOL_COLOR QColor(128,128,128) // any bg
#define NORMAL_PAGETOOL_HIGHLIGHT_COLOR QColor(64,64,64) // on white
@ -204,6 +206,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
iInvertColorsConf(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
iCurrentFolderConf(new MGConfItem(DCONF_PATH KEY_CURRENT_FOLDER, this)),
iCurrentBookPathConf(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
iOrientationConf(new MGConfItem(DCONF_PATH KEY_ORIENTATION, this)),
iCurrentBook(NULL),
iFontSize(currentFontSize())
{
@ -214,6 +217,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
connect(iInvertColorsConf, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
connect(iCurrentFolderConf, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
connect(iCurrentBookPathConf, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
connect(iOrientationConf, SIGNAL(valueChanged()), SIGNAL(orientationChanged()));
}
bool
@ -453,3 +457,19 @@ BooksSettings::highlightPageToolColor() const
INVERTED_PAGETOOL_HIGHLIGHT_COLOR :
NORMAL_PAGETOOL_HIGHLIGHT_COLOR;
}
BooksSettings::Orientation
BooksSettings::orientation() const
{
// Need to cast int to enum right away to force "enumeration value not
// handled in switch" warning if we miss one of the Orientation:
Orientation value = (Orientation)
iOrientationConf->value(DEFAULT_ORIENTATION).toInt();
switch (value) {
case OrientationAny:
case OrientationPortrait:
case OrientationLandscape:
return value;
}
return DEFAULT_ORIENTATION;
}

View file

@ -45,6 +45,7 @@ class BooksSettings : public QObject
{
Q_OBJECT
Q_ENUMS(FontSize)
Q_ENUMS(Orientation)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged)
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged)
@ -54,6 +55,7 @@ class BooksSettings : public QObject
Q_PROPERTY(QString relativePath READ relativePath NOTIFY relativePathChanged)
Q_PROPERTY(QColor primaryPageToolColor READ primaryPageToolColor CONSTANT)
Q_PROPERTY(QColor highlightPageToolColor READ highlightPageToolColor NOTIFY invertColorsChanged)
Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged)
class TextStyle;
public:
@ -64,12 +66,18 @@ public:
FontSizeSteps = MaxFontSize - MinFontSize
};
enum Orientation {
OrientationAny,
OrientationPortrait,
OrientationLandscape
};
explicit BooksSettings(QObject* aParent = NULL);
Q_INVOKABLE bool increaseFontSize();
Q_INVOKABLE bool decreaseFontSize();
int fontSize() const { return iFontSize; }
int fontSize() const;
void setFontSize(int aValue);
int pageDetails() const;
@ -87,10 +95,12 @@ public:
QString currentFolder() const;
void setCurrentFolder(QString aValue);
QString currentStorage() const { return iCurrentStorageDevice; }
QString currentStorage() const;
QColor primaryPageToolColor() const;
QColor highlightPageToolColor() const;
Orientation orientation() const;
Q_SIGNALS:
void fontSizeChanged();
void textStyleChanged();
@ -100,6 +110,7 @@ Q_SIGNALS:
void currentFolderChanged();
void currentStorageChanged();
void relativePathChanged();
void orientationChanged();
private Q_SLOTS:
void onFontSizeValueChanged();
@ -119,6 +130,7 @@ private:
MGConfItem* iInvertColorsConf;
MGConfItem* iCurrentFolderConf;
MGConfItem* iCurrentBookPathConf;
MGConfItem* iOrientationConf;
mutable shared_ptr<ZLTextStyle> iTextStyle[FontSizeSteps+1];
BooksBook* iCurrentBook;
QString iCurrentStorageDevice;
@ -127,4 +139,9 @@ private:
QML_DECLARE_TYPE(BooksSettings)
inline int BooksSettings::fontSize() const
{ return iFontSize; }
inline QString BooksSettings::currentStorage() const
{ return iCurrentStorageDevice; }
#endif // BOOKS_SETTINGS_H

View file

@ -65,7 +65,7 @@
<message id="harbour-books-storage-menu-settings">
<source>Settings</source>
<extracomment>Pulley menu item</extracomment>
<translation type="unfinished">Einstellungen</translation>
<translation>Einstellungen</translation>
</message>
<message id="harbour-books-storage-menu-scan_downloads">
<source>Scan downloads</source>
@ -114,5 +114,25 @@
<extracomment>Slider value label for the standard font size</extracomment>
<translation>Standard</translation>
</message>
<message id="harbour-books-settings-page-orientation_label">
<source>Orientation</source>
<extracomment>Combo box label</extracomment>
<translation>Orientierung</translation>
</message>
<message id="harbour-books-settings-page-orientation-dynamic">
<source>Dynamic</source>
<extracomment>Combo box value for dynamic orientation</extracomment>
<translation>Dynamisch</translation>
</message>
<message id="harbour-books-settings-page-orientation-portrait">
<source>Portrait</source>
<extracomment>Combo box value for portrait orientation</extracomment>
<translation>Hochformat</translation>
</message>
<message id="harbour-books-settings-page-orientation-landscape">
<source>Landscape</source>
<extracomment>Combo box value for landscape orientation</extracomment>
<translation>Querformat</translation>
</message>
</context>
</TS>

View file

@ -114,5 +114,25 @@
<extracomment>Slider value label for the standard font size</extracomment>
<translation type="unfinished">Oletus</translation>
</message>
<message id="harbour-books-settings-page-orientation_label">
<source>Orientation</source>
<extracomment>Combo box label</extracomment>
<translation>Suunta</translation>
</message>
<message id="harbour-books-settings-page-orientation-dynamic">
<source>Dynamic</source>
<extracomment>Combo box value for dynamic orientation</extracomment>
<translation>Dynaaminen</translation>
</message>
<message id="harbour-books-settings-page-orientation-portrait">
<source>Portrait</source>
<extracomment>Combo box value for portrait orientation</extracomment>
<translation>Pysty</translation>
</message>
<message id="harbour-books-settings-page-orientation-landscape">
<source>Landscape</source>
<extracomment>Combo box value for landscape orientation</extracomment>
<translation>Vaaka</translation>
</message>
</context>
</TS>

View file

@ -116,5 +116,25 @@
<extracomment>Slider value label for the standard font size</extracomment>
<translation>Стандартный</translation>
</message>
<message id="harbour-books-settings-page-orientation_label">
<source>Orientation</source>
<extracomment>Combo box label</extracomment>
<translation>Ориентация</translation>
</message>
<message id="harbour-books-settings-page-orientation-dynamic">
<source>Dynamic</source>
<extracomment>Combo box value for dynamic orientation</extracomment>
<translation>Динамическая</translation>
</message>
<message id="harbour-books-settings-page-orientation-portrait">
<source>Portrait</source>
<extracomment>Combo box value for portrait orientation</extracomment>
<translation>Портретная</translation>
</message>
<message id="harbour-books-settings-page-orientation-landscape">
<source>Landscape</source>
<extracomment>Combo box value for landscape orientation</extracomment>
<translation>Альбомная</translation>
</message>
</context>
</TS>

View file

@ -114,5 +114,25 @@
<extracomment>Slider value label for the standard font size</extracomment>
<translation type="unfinished">Standard</translation>
</message>
<message id="harbour-books-settings-page-orientation_label">
<source>Orientation</source>
<extracomment>Combo box label</extracomment>
<translation>Orientering</translation>
</message>
<message id="harbour-books-settings-page-orientation-dynamic">
<source>Dynamic</source>
<extracomment>Combo box value for dynamic orientation</extracomment>
<translation>Dynamisk</translation>
</message>
<message id="harbour-books-settings-page-orientation-portrait">
<source>Portrait</source>
<extracomment>Combo box value for portrait orientation</extracomment>
<translation>Stående</translation>
</message>
<message id="harbour-books-settings-page-orientation-landscape">
<source>Landscape</source>
<extracomment>Combo box value for landscape orientation</extracomment>
<translation>Liggande</translation>
</message>
</context>
</TS>

View file

@ -114,5 +114,25 @@
<extracomment>Slider value label for the standard font size</extracomment>
<translation>Default</translation>
</message>
<message id="harbour-books-settings-page-orientation_label">
<source>Orientation</source>
<extracomment>Combo box label</extracomment>
<translation>Orientation</translation>
</message>
<message id="harbour-books-settings-page-orientation-dynamic">
<source>Dynamic</source>
<extracomment>Combo box value for dynamic orientation</extracomment>
<translation>Dynamic</translation>
</message>
<message id="harbour-books-settings-page-orientation-portrait">
<source>Portrait</source>
<extracomment>Combo box value for portrait orientation</extracomment>
<translation>Portrait</translation>
</message>
<message id="harbour-books-settings-page-orientation-landscape">
<source>Landscape</source>
<extracomment>Combo box value for landscape orientation</extracomment>
<translation>Landscape</translation>
</message>
</context>
</TS>