Skip to content

Commit

Permalink
Commit before adding new development branch
Browse files Browse the repository at this point in the history
- changed how new instance arguments work to ensure it works properly in
case OS adds it's own arguments on application start.
It will require "-i newInstance" in order for a new clean instance to
start.
This was added because I noticed KDE adds another argument at startup.
- removed Stackview from mainWindow as it was unnecessary
- changed font of the tray icon
- created a custom image provider which is used to show "Provided by
OpenWeatherMap" when their API is used, since their logo is square and
wouldn't fit properly in that space
  • Loading branch information
vadrian89 committed Apr 25, 2017
1 parent d43b46d commit 4a08abf
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 56 deletions.
48 changes: 48 additions & 0 deletions CppFiles/CustomImageProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2017 Adrian Verban <[email protected]>
* Maintainers: Adrian Verban <[email protected]>
* Derived from Typhoon by Archisman Panigrahi which is based on Stormcloud by Jono Cooper <jonocooper.com>
* Thanks to all the contributors.
* Using the Ubuntu Condensed font.
* This file is part of Cumulus.
#
* Cumulus 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 3 of the License, or
* (at your option) any later version.
#
* Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CustomImageProvider.h"
#include "Util.h"

CustomImageProvider::CustomImageProvider() : QQuickImageProvider(QQuickImageProvider::Image) {}

QImage CustomImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) {
Q_UNUSED(size)
Q_UNUSED(requestedSize)
if (id == "owm-logo") {
return getImageFromText("Provided by:\nOpenWeatherMap", Util::textColor(), 268, 58);
}
else {
return getImageFromText("", Util::textColor(), 268, 58);
}
}

QImage CustomImageProvider::getImageFromText(const QString &text, const QString &color, const int &width, const int &height) {
QImage image(width, height, QImage::Format_ARGB32_Premultiplied);
QFont font;
font.setPixelSize(24);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setFont(font);
painter.setPen(QColor(color));
painter.drawText(image.rect(), Qt::AlignCenter, text);
return image;
}
35 changes: 35 additions & 0 deletions CppFiles/CustomImageProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2017 Adrian Verban <[email protected]>
* Maintainers: Adrian Verban <[email protected]>
* Derived from Typhoon by Archisman Panigrahi which is based on Stormcloud by Jono Cooper <jonocooper.com>
* Thanks to all the contributors.
* Using the Ubuntu Condensed font.
* This file is part of Cumulus.
#
* Cumulus 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 3 of the License, or
* (at your option) any later version.
#
* Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CUSTOMIMAGEPROVIDER_H
#define CUSTOMIMAGEPROVIDER_H

#include <QQuickImageProvider>
#include <QImage>

class CustomImageProvider : public QQuickImageProvider {
public:
CustomImageProvider();
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
QImage getImageFromText(const QString &text, const QString &color, const int &width, const int &height);
};

#endif // CUSTOMIMAGEPROVIDER_H
7 changes: 6 additions & 1 deletion CppFiles/ThreadWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ void ThreadWorker::startLookingForUpdates() {

void ThreadWorker::createWeatherPixmap(const QString &weather) {
QImage image(22, 22, QImage::Format_ARGB32_Premultiplied);
QFont font;
font.setPixelSize(14);
font.setFamily("Arial");
font.setBold(true);
image.fill(Qt::transparent);
QPainter painter(&image);
painter.setFont(font);
painter.setPen(QColor(Qt::white));
painter.setRenderHint(QPainter::Antialiasing);
painter.drawText(QRect(0,0, 22, 22), Qt::AlignCenter, weather);
painter.drawText(image.rect(), Qt::AlignCenter, weather);
emit finishedCreatingPixmap(image);
emit stopThread();
}
2 changes: 1 addition & 1 deletion CppFiles/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ QString Util::getLogoImage() {
}
else {
getLogoImage("Provided by:\nOpenWeatherMap", textColor());
return getLogoImage("Provided by:\nOpenWeatherMap", textColor());
return "image://customimage/owm-logo";
}
}

Expand Down
6 changes: 4 additions & 2 deletions Cumulus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ SOURCES += main.cpp \
CppFiles/WeatherType.cpp \
CppFiles/AbstractWeatherController.cpp \
CppFiles/TrayController.cpp \
CppFiles/CreditsAuthor.cpp
CppFiles/CreditsAuthor.cpp \
CppFiles/CustomImageProvider.cpp

RESOURCES += qml.qrc

Expand All @@ -38,7 +39,8 @@ HEADERS += \
CppFiles/WeatherType.h \
CppFiles/AbstractWeatherController.h \
CppFiles/TrayController.h \
CppFiles/CreditsAuthor.h
CppFiles/CreditsAuthor.h \
CppFiles/CustomImageProvider.h

QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/lib\'"

Expand Down
8 changes: 6 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@
#include "CppFiles/SearchLocation.h"
#include "CppFiles/TrayController.h"
#include "CppFiles/ThreadWorker.h"
#include "CppFiles/CustomImageProvider.h"

void registerQmlType();

#include <QDebug>
int main(int argc, char *argv[]) {
QString applicationName = argc > 1 ? argv[1] : "Cumulus";
QString applicationName = "Cumulus";
if (argc > 2 && QString::fromLatin1(argv[2]) == "-i") {
applicationName = argv[3];
}
QCoreApplication::setOrganizationName("Visoft");
QCoreApplication::setApplicationName(applicationName);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
Util util;
QThread thread;
QQmlApplicationEngine engine;
engine.addImageProvider(QLatin1String("customimage"), new CustomImageProvider());
QQmlContext *context = engine.rootContext();
context->setContextProperty("util", &util);
context->setContextProperty("applicationPath", "file://" + qApp->applicationDirPath() + "/");
Expand Down
97 changes: 47 additions & 50 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2

import ownTypes.settingsController 0.5
Expand All @@ -35,6 +35,8 @@ ApplicationWindow {
property int winMinHeight: 150
property int winMinWidth: 140
property int widthBreakPoint: 170
property int minimumX: (Screen.width - Screen.desktopAvailableWidth)
property int minimumY: (Screen.height - Screen.desktopAvailableHeight)
visible: util.trayVisibility() == true ? false : true
minimumHeight: winMinHeight
minimumWidth: winMinWidth
Expand All @@ -44,12 +46,13 @@ ApplicationWindow {
y: mainWindowLocation.y
title: qsTr("Cumulus")
color: "transparent"
flags: Qt.FramelessWindowHint
flags: Qt.CustomizeWindowHint

FontLoader {
id: ubuntuCondensed
source: "fonts/Ubuntu-C.ttf"
}

FontLoader {
id: weatherIcons
source: "fonts/weathericons-regular-webfont.ttf"
Expand All @@ -61,7 +64,7 @@ ApplicationWindow {
}

onClosing: {
util.saveWindowSize(Qt.size(width, height))
util.saveWindowSize(Qt.size(mainWindow.width, mainWindow.height))
if (applicationSettingsController.trayVisibility == true) {
visible = false
}
Expand Down Expand Up @@ -102,13 +105,13 @@ ApplicationWindow {
mainWindow.y = mainWindow.y + delta.y
}
moveControlAlias.onReleased: {
if (mainWindow.x < 70 ) {
mainWindow.x = 0
if (mainWindow.x <= minimumX ) {
mainWindow.x = minimumX
}
if (mainWindow.y < 70 ) {
mainWindow.y = 0
if (mainWindow.y <= minimumY ) {
mainWindow.y = minimumY
}
util.saveWindowLocation(Qt.point(mainWindow.x, mainWindow.y));
util.saveWindowLocation(Qt.point(mainWindow.x, mainWindow.y))
moveControlAlias.cursorShape = Qt.ArrowCursor
mainWindow.maximumHeight = Screen.desktopAvailableHeight
mainWindow.maximumWidth = Screen.desktopAvailableWidth
Expand All @@ -119,54 +122,48 @@ ApplicationWindow {
animationAlias.onStarted: weatherView.loadingEnded = false
}

StackView {
id: appView
Flickable {
id: bodyView
anchors.top: applicationBar.bottom
width: parent.width
height: parent.height - applicationBar.height
initialItem: bodyView
anchors.top: applicationBar.bottom
Flickable {
id: bodyView
contentHeight: height
contentWidth: width
interactive: false
contentX: 0
contentHeight: bodyView.height
contentWidth: bodyView.width
interactive: false
contentX: 0

WeatherWindow {
id: weatherView
width: bodyView.width
height: bodyView.height
textColor: applicationSettingsController.textColor
textFontFamily: ubuntuCondensed.name
iconsFont: weatherIcons.name
speedUnit: settingsView.speedUnit
widthBreakPoint: mainWindow.widthBreakPoint
visible: false
onNoLocationDetected: {
settingsViewDialog.visible = true
settingsView.searchLocationAlias.visible = true
applicationBar.menuButtonAlias.visible = false
applicationBar.refreshButtonAlias.visible = false
}
onFinishedWeatherUpdate: {
visible = true
applicationBar.menuButtonAlias.visible = true
applicationBar.refreshButtonAlias.visible = true
}
onUpdateWeather: {
if (applicationBar.animationAlias.running == false) {
applicationBar.animationAlias.start()
applicationBar.animationAlias.loops = RotationAnimation.Infinite
}
}
onDataDownloadFinished: {
applicationBar.animationAlias.stop()
timer.interval = 3600000
WeatherWindow {
id: weatherView
width: bodyView.width
height: bodyView.height
textColor: applicationSettingsController.textColor
textFontFamily: ubuntuCondensed.name
iconsFont: weatherIcons.name
speedUnit: settingsView.speedUnit
widthBreakPoint: mainWindow.widthBreakPoint
visible: false
onNoLocationDetected: {
settingsViewDialog.visible = true
settingsView.searchLocationAlias.visible = true
applicationBar.menuButtonAlias.visible = false
applicationBar.refreshButtonAlias.visible = false
}
onFinishedWeatherUpdate: {
visible = true
applicationBar.menuButtonAlias.visible = true
applicationBar.refreshButtonAlias.visible = true
}
onUpdateWeather: {
if (applicationBar.animationAlias.running == false) {
applicationBar.animationAlias.start()
applicationBar.animationAlias.loops = RotationAnimation.Infinite
}
}
onDataDownloadFinished: {
applicationBar.animationAlias.stop()
timer.interval = 3600000
}
}


}
}
Component.onCompleted: weatherView.updateWeather()
Expand Down

0 comments on commit 4a08abf

Please sign in to comment.