@@ -0,0 +1,72 @@ | |||
/* | |||
* Carla Qt4 Style, based on Qt5 fusion style | |||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies) | |||
* | |||
* 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 3 of | |||
* the License, or 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. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL3.txt file | |||
*/ | |||
#ifndef __CARLA_STYLE_HPP__ | |||
#define __CARLA_STYLE_HPP__ | |||
#include <QtGui/QCommonStyle> | |||
#include <QtGui/QStylePlugin> | |||
class CarlaStylePrivate; | |||
class CarlaStyle : public QCommonStyle | |||
{ | |||
Q_OBJECT | |||
public: | |||
CarlaStyle(); | |||
~CarlaStyle(); | |||
QPalette standardPalette() const; | |||
void drawPrimitive(PrimitiveElement elem, | |||
const QStyleOption *option, | |||
QPainter *painter, const QWidget *widget = 0) const; | |||
void drawControl(ControlElement ce, const QStyleOption *option, QPainter *painter, | |||
const QWidget *widget) const; | |||
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const; | |||
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, | |||
QPainter *painter, const QWidget *widget) const; | |||
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = 0) const; | |||
QSize sizeFromContents(ContentsType type, const QStyleOption *option, | |||
const QSize &size, const QWidget *widget) const; | |||
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, | |||
SubControl sc, const QWidget *widget) const; | |||
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, | |||
QStyleHintReturn *returnData = 0) const; | |||
void drawItemText(QPainter *painter, const QRect &rect, | |||
int flags, const QPalette &pal, bool enabled, | |||
const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const; | |||
void polish(QWidget *widget); | |||
void unpolish(QWidget *widget); | |||
private: | |||
CarlaStylePrivate* const d; | |||
friend class CarlaStylePrivate; | |||
}; | |||
class CarlaStylePlugin : public QStylePlugin | |||
{ | |||
Q_OBJECT | |||
public: | |||
CarlaStylePlugin(QObject* parent = nullptr); | |||
QStyle* create(const QString& key); | |||
QStringList keys() const; | |||
}; | |||
#endif // __CARLA_STYLE_HPP__ |
@@ -0,0 +1,177 @@ | |||
/* | |||
* Carla Qt4 Style, based on Qt5 fusion style | |||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies) | |||
* | |||
* 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 3 of | |||
* the License, or 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. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL3.txt file | |||
*/ | |||
#ifndef __CARLA_STYLE_ANIMATIONS_HPP__ | |||
#define __CARLA_STYLE_ANIMATIONS_HPP__ | |||
#include <QtCore/QAbstractAnimation> | |||
#include <QtCore/QCoreApplication> | |||
#include <QtCore/QDateTime> | |||
#include <QtGui/QImage> | |||
#include <QtGui/QWidget> | |||
class CarlaStyleAnimation : public QAbstractAnimation | |||
{ | |||
Q_OBJECT | |||
public: | |||
CarlaStyleAnimation(QObject* target) | |||
: QAbstractAnimation(), | |||
_delay(0), | |||
_duration(-1), | |||
_startTime(QTime::currentTime()) | |||
{ | |||
if (target != nullptr) | |||
{ | |||
moveToThread(target->thread()); | |||
setParent(target); | |||
} | |||
connect(this, SIGNAL(finished()), SLOT(deleteLater())); | |||
} | |||
virtual ~CarlaStyleAnimation() | |||
{ | |||
} | |||
QObject* target() const | |||
{ | |||
return parent(); | |||
} | |||
int duration() const | |||
{ | |||
return _duration; | |||
} | |||
void setDuration(int duration) | |||
{ | |||
_duration = duration; | |||
} | |||
int delay() const | |||
{ | |||
return _delay; | |||
} | |||
void setDelay(int delay) | |||
{ | |||
_delay = delay; | |||
} | |||
QTime startTime() const | |||
{ | |||
return _startTime; | |||
} | |||
void setStartTime(const QTime& time) | |||
{ | |||
_startTime = time; | |||
} | |||
void updateTarget() | |||
{ | |||
QEvent event(QEvent::HoverEnter); | |||
QCoreApplication::sendEvent(target(), &event); | |||
} | |||
protected: | |||
virtual bool isUpdateNeeded() const | |||
{ | |||
return currentTime() > _delay; | |||
} | |||
virtual void updateCurrentTime(int /*time*/) | |||
{ | |||
if (QObject* tgt = target()) | |||
{ | |||
if (tgt->isWidgetType()) | |||
{ | |||
QWidget* widget = static_cast<QWidget*>(tgt); | |||
if (widget->window()->isMinimized() || ! widget->isVisible()) | |||
stop(); | |||
} | |||
if (isUpdateNeeded()) | |||
updateTarget(); | |||
} | |||
} | |||
private: | |||
int _delay; | |||
int _duration; | |||
QTime _startTime; | |||
}; | |||
class CarlaProgressStyleAnimation : public CarlaStyleAnimation | |||
{ | |||
Q_OBJECT | |||
public: | |||
CarlaProgressStyleAnimation(int speed, QObject* target) | |||
: CarlaStyleAnimation(target), | |||
_speed(speed), | |||
_step(-1) | |||
{ | |||
} | |||
int animationStep() const | |||
{ | |||
return currentTime() / (1000.0 / _speed); | |||
} | |||
int progressStep(int width) const | |||
{ | |||
int step = animationStep(); | |||
int progress = (step * width / _speed) % width; | |||
if (((step * width / _speed) % (2 * width)) >= width) | |||
progress = width - progress; | |||
return progress; | |||
} | |||
int speed() const | |||
{ | |||
return _speed; | |||
} | |||
void setSpeed(int speed) | |||
{ | |||
_speed = speed; | |||
} | |||
protected: | |||
bool isUpdateNeeded() const | |||
{ | |||
if (CarlaStyleAnimation::isUpdateNeeded()) | |||
{ | |||
int current = animationStep(); | |||
if (_step == -1 || _step != current) | |||
{ | |||
_step = current; | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private: | |||
int _speed; | |||
mutable int _step; | |||
}; | |||
#endif // __CARLA_STYLE_ANIMATIONS_HPP__ |
@@ -0,0 +1,160 @@ | |||
/* | |||
* Carla Qt4 Style, based on Qt5 fusion style | |||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies) | |||
* | |||
* 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 3 of | |||
* the License, or 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. | |||
* | |||
* For a full copy of the GNU General Public License see the GPL3.txt file | |||
*/ | |||
#ifndef __CARLA_STYLE_PRIVATE_HPP__ | |||
#define __CARLA_STYLE_PRIVATE_HPP__ | |||
#include "CarlaStyle.hpp" | |||
#include "CarlaStyleAnimations.hpp" | |||
#include <QtCore/QHash> | |||
class QStyleAnimation; | |||
class CarlaStylePrivate : public QObject | |||
{ | |||
Q_OBJECT | |||
public: | |||
enum { | |||
menuItemHMargin = 3, // menu item hor text margin | |||
menuArrowHMargin = 6, // menu arrow horizontal margin | |||
menuRightBorder = 15, // right border on menus | |||
menuCheckMarkWidth = 12 // checkmarks width on menus | |||
}; | |||
CarlaStylePrivate(CarlaStyle* const style) | |||
: kStyle(style), | |||
fAnimationFps(60) | |||
{ | |||
} | |||
~CarlaStylePrivate() | |||
{ | |||
qDeleteAll(fAnimations); | |||
} | |||
int animationFps() const | |||
{ | |||
return fAnimationFps; | |||
} | |||
// Used for grip handles | |||
QColor lightShade() const | |||
{ | |||
return QColor(102, 102, 102, 90); | |||
} | |||
QColor darkShade() const | |||
{ | |||
return QColor(0, 0, 0, 60); | |||
} | |||
QColor topShadow() const | |||
{ | |||
return QColor(0, 0, 0, 18); | |||
} | |||
QColor innerContrastLine() const | |||
{ | |||
return QColor(255, 255, 255, 30); | |||
} | |||
QColor highlight(const QPalette& pal) const | |||
{ | |||
return pal.color(QPalette::Active, QPalette::Highlight); | |||
} | |||
QColor highlightedText(const QPalette& pal) const | |||
{ | |||
return pal.color(QPalette::Active, QPalette::HighlightedText); | |||
} | |||
QColor outline(const QPalette& pal) const | |||
{ | |||
if (! pal.window().texture().isNull()) | |||
return QColor(0, 0, 0, 160); | |||
return pal.background().color().darker(140); | |||
} | |||
QColor highlightedOutline(const QPalette &pal) const | |||
{ | |||
QColor highlightedOutline = highlight(pal).darker(125); | |||
if (highlightedOutline.value() > 160) | |||
highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160); | |||
return highlightedOutline; | |||
} | |||
QColor tabFrameColor(const QPalette& pal) const | |||
{ | |||
if (! pal.button().texture().isNull()) | |||
return QColor(255, 255, 255, 8); | |||
return buttonColor(pal).lighter(104); | |||
} | |||
QColor buttonColor(const QPalette& pal) const | |||
{ | |||
QColor buttonColor = pal.button().color(); | |||
int val = qGray(buttonColor.rgb()); | |||
buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6)); | |||
buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value()); | |||
return buttonColor; | |||
} | |||
QIcon tabBarcloseButtonIcon; | |||
QList<const QObject*> animationTargets() const | |||
{ | |||
return fAnimations.keys(); | |||
} | |||
CarlaStyleAnimation* animation(const QObject* target) const | |||
{ | |||
return fAnimations.value(target); | |||
} | |||
void startAnimation(CarlaStyleAnimation* animation) const | |||
{ | |||
stopAnimation(animation->target()); | |||
kStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection); | |||
fAnimations.insert(animation->target(), animation); | |||
animation->start(); | |||
} | |||
void stopAnimation(const QObject* target) const | |||
{ | |||
CarlaStyleAnimation* animation = fAnimations.take(target); | |||
if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped) | |||
animation->stop(); | |||
} | |||
private: | |||
CarlaStyle* const kStyle; | |||
int fAnimationFps; | |||
mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations; | |||
private slots: | |||
void _removeAnimation() | |||
{ | |||
QObject* animation = kStyle->sender(); | |||
if (animation != nullptr) | |||
fAnimations.remove(animation->parent()); | |||
} | |||
}; | |||
#endif // __CARLA_STYLE_PRIVATE_HPP__ |
@@ -0,0 +1,59 @@ | |||
#!/usr/bin/make -f | |||
# Makefile for theme # | |||
# ------------------ # | |||
# Created by falkTX | |||
# | |||
include ../Makefile.mk | |||
# -------------------------------------------------------------- | |||
BUILD_CXX_FLAGS += -fvisibility=hidden -I. | |||
ifeq ($(HAVE_QT5),true) | |||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets) | |||
LINK_FLAGS += $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets) | |||
else | |||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore QtGui) | |||
LINK_FLAGS += $(shell pkg-config --libs QtCore QtGui) | |||
endif | |||
FILES = \ | |||
moc_CarlaStyle.cpp \ | |||
moc_CarlaStylePrivate.cpp \ | |||
moc_CarlaStyleAnimations.cpp \ | |||
resources.cpp | |||
OBJS = \ | |||
CarlaStyle.cpp.o \ | |||
moc_CarlaStyle.cpp.o \ | |||
moc_CarlaStyleAnimations.cpp.o \ | |||
moc_CarlaStylePrivate.cpp.o | |||
TARGET = ../libs/theme.a | |||
# -------------------------------------------------------------- | |||
all: $(TARGET) | |||
clean: | |||
rm -f $(FILES) $(OBJS) $(TARGET) | |||
debug: | |||
$(MAKE) DEBUG=true | |||
# -------------------------------------------------------------- | |||
$(TARGET): $(FILES) $(OBJS) | |||
$(AR) rs $@ $(OBJS) | |||
# -------------------------------------------------------------- | |||
%.cpp.o: %.cpp CarlaStyle.hpp moc_CarlaStyle.cpp | |||
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ | |||
moc_%.cpp: %.hpp | |||
$(MOC) $< -o $@ | |||
resources.cpp: ../../resources/resources-theme.qrc | |||
$(RCC) $< -o $@ |