summaryrefslogtreecommitdiff
path: root/src/moapplication.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-04-05 15:36:42 +0200
committerTannin <devnull@localhost>2014-04-05 15:36:42 +0200
commitcabed9b268c9f095d5e3b98a6797b0bcdcd38b1f (patch)
tree454b03b0c5664e90fe586e7b39603e34a526d35b /src/moapplication.cpp
parent98e5e57a845541acddf519a81957261f58008cb9 (diff)
parentc017f4a0d50b67a44e276bd5ae8929ed3990c62c (diff)
Merge with branch1.1
Diffstat (limited to 'src/moapplication.cpp')
-rw-r--r--src/moapplication.cpp86
1 files changed, 77 insertions, 9 deletions
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index efb0b615..12ff713b 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -19,20 +19,70 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "moapplication.h"
#include "report.h"
-#include "utility.h"
+#include <utility.h>
#include <appconfig.h>
#include <QFile>
#include <QStringList>
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
+#include <QPlastiqueStyle>
+#include <QCleanlooksStyle>
+#endif
+#include <QProxyStyle>
+#include <QStyleFactory>
+#include <QPainter>
+#include <QStyleOption>
+
+
+#include <QDebug>
+
+
+class ProxyStyle : public QProxyStyle {
+public:
+ ProxyStyle(QStyle *baseStyle = 0)
+ : QProxyStyle(baseStyle)
+ {
+ }
+
+ void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
+ if(element == QStyle::PE_IndicatorItemViewItemDrop) {
+ painter->setRenderHint(QPainter::Antialiasing, true);
+
+ QColor col(option->palette.foreground().color());
+ QPen pen(col);
+ pen.setWidth(2);
+ col.setAlpha(50);
+ QBrush brush(col);
+
+ painter->setPen(pen);
+ painter->setBrush(brush);
+ if(option->rect.height() == 0) {
+ QPoint tri[3] = {
+ option->rect.topLeft(),
+ option->rect.topLeft() + QPoint(-5, 5),
+ option->rect.topLeft() + QPoint(-5, -5)
+ };
+ painter->drawPolygon(tri, 3);
+ painter->drawLine(QPoint(option->rect.topLeft().x(), option->rect.topLeft().y()), option->rect.topRight());
+ } else {
+ painter->drawRoundedRect(option->rect, 5, 5);
+ }
+ } else {
+ QProxyStyle::drawPrimitive(element, option, painter, widget);
+ }
+ }
+};
MOApplication::MOApplication(int argc, char **argv)
: QApplication(argc, argv)
{
connect(&m_StyleWatcher, SIGNAL(fileChanged(QString)), SLOT(updateStyle(QString)));
+ m_DefaultStyle = style()->objectName();
+ setStyle(new ProxyStyle(style()));
}
-void MOApplication::setStyleFile(const QString &styleName)
+bool MOApplication::setStyleFile(const QString &styleName)
{
// remove all files from watch
QStringList currentWatch = m_StyleWatcher.files();
@@ -42,11 +92,16 @@ void MOApplication::setStyleFile(const QString &styleName)
// set new stylesheet or clear it
if (styleName.length() != 0) {
QString styleSheetName = applicationDirPath() + "/" + MOBase::ToQString(AppConfig::stylesheetsPath()) + "/" + styleName;
- m_StyleWatcher.addPath(styleSheetName);
- updateStyle(styleSheetName);
+ if (QFile::exists(styleSheetName)) {
+ m_StyleWatcher.addPath(styleSheetName);
+ updateStyle(styleSheetName);
+ } else {
+ updateStyle(styleName);
+ }
} else {
setStyleSheet("");
}
+ return true;
}
@@ -70,11 +125,24 @@ bool MOApplication::notify(QObject *receiver, QEvent *event)
void MOApplication::updateStyle(const QString &fileName)
{
- QFile file(fileName);
- if (file.open(QFile::ReadOnly)) {
- setStyleSheet(file.readAll());
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+ if (fileName == "Fusion") {
+ setStyle(QStyleFactory::create("fusion"));
+ setStyleSheet("");
+#else
+ if (fileName == "Plastique") {
+ setStyle(new ProxyStyle(new QPlastiqueStyle));
+ setStyleSheet("");
+ } else if (fileName == "Cleanlooks") {
+ setStyle(new ProxyStyle(new QCleanlooksStyle));
+ setStyleSheet("");
+#endif
} else {
- qDebug("no stylesheet");
+ setStyle(new ProxyStyle(QStyleFactory::create(m_DefaultStyle)));
+ if (QFile::exists(fileName)) {
+ setStyleSheet(QString("file:///%1").arg(fileName));
+ } else {
+ qWarning("invalid stylesheet: %s", qPrintable(fileName));
+ }
}
- file.close();
}