Stylesheet for system theme now works

This commit is contained in:
Max Sandholm 2017-10-30 14:34:12 +02:00
parent 9521e692c0
commit ee893c5adf
10 changed files with 71 additions and 11 deletions

View File

@ -38,6 +38,15 @@ struct DescInfo
class RoomInfoListItem : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor highlightedBackgroundColor
READ highlightedBackgroundColor
WRITE setHighlightedBackgroundColor)
Q_PROPERTY(QColor hoverBackgroundColor
READ hoverBackgroundColor
WRITE setHoverBackgroundColor)
Q_PROPERTY(QColor backgroundColor
READ backgroundColor
WRITE setBackgroundColor)
public:
RoomInfoListItem(QSharedPointer<RoomSettings> settings,
@ -51,13 +60,21 @@ public:
void clearUnreadMessageCount();
void setState(const RoomState &state);
bool isPressed() const { return isPressed_; };
RoomState state() const { return state_; };
int unreadMessageCount() const { return unreadMsgCount_; };
bool isPressed() const { return isPressed_; }
RoomState state() const { return state_; }
int unreadMessageCount() const { return unreadMsgCount_; }
void setAvatar(const QImage &avatar_image);
void setDescriptionMessage(const DescInfo &info);
inline QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
inline QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
inline QColor backgroundColor() const { return backgroundColor_; }
inline void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; }
inline void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; }
inline void setBackgroundColor(QColor &color) { backgroundColor_ = color; }
signals:
void clicked(const QString &room_id);
void leaveRoom(const QString &room_id);
@ -98,4 +115,8 @@ private:
int maxHeight_;
int unreadMsgCount_ = 0;
QColor highlightedBackgroundColor_;
QColor hoverBackgroundColor_;
QColor backgroundColor_;
};

View File

@ -19,6 +19,9 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include "Emote.h"
#include "Image.h"
@ -67,6 +70,9 @@ public:
~TimelineItem();
protected:
void paintEvent(QPaintEvent *event) override;
private:
void init();

View File

@ -21,6 +21,8 @@
#include <QList>
#include <QQueue>
#include <QScrollArea>
#include <QStyle>
#include <QStyleOption>
#include "Emote.h"
#include "Image.h"
@ -120,6 +122,9 @@ private slots:
signals:
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
protected:
void paintEvent(QPaintEvent *event) override;
private:
void init();
void addTimelineItem(TimelineItem *item, TimelineDirection direction);

View File

@ -1,2 +1,13 @@
TimelineView { background-color: red; }
TimelineItem { background-color: rgba(255,0,0,255); }
TimelineView, TimelineView > * {
background-color: palette(base);
}
FlatButton {
qproperty-foregroundColor: palette(text);
}
RoomInfoListItem {
qproperty-highlightedBackgroundColor: palette(highlight);
qproperty-hoverBackgroundColor: palette(dark);
qproperty-backgroundColor: palette(window);
}

View File

@ -54,7 +54,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
topLayout_->setMargin(0);
auto splitter = new Splitter(this);
splitter->setHandleWidth(1);
splitter->setHandleWidth(0);
topLayout_->addWidget(splitter);

View File

@ -96,11 +96,11 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
p.setRenderHint(QPainter::Antialiasing);
if (isPressed_)
p.fillRect(rect(), palette().color(QPalette::Highlight));
p.fillRect(rect(), highlightedBackgroundColor_);
else if (underMouse())
p.fillRect(rect(), palette().color(QPalette::Dark));
p.fillRect(rect(), hoverBackgroundColor_);
else
p.fillRect(rect(), palette().color(QPalette::Window));
p.fillRect(rect(), backgroundColor_);
QFont font;
font.setPixelSize(conf::fontSize);

View File

@ -468,3 +468,12 @@ TimelineItem::descriptiveTime(const QDateTime &then)
}
TimelineItem::~TimelineItem() {}
void
TimelineItem::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View File

@ -639,3 +639,12 @@ TimelineView::handleFailedMessage(int txnid)
// Note: We do this even if the message has already been echoed.
QTimer::singleShot(500, this, SLOT(sendNextPendingMessage()));
}
void
TimelineView::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View File

@ -22,6 +22,7 @@
#include <QNetworkProxy>
#include <QSettings>
#include <QTranslator>
#include <QFile>
#include "MainWindow.h"

View File

@ -197,8 +197,6 @@ TextField::paintEvent(QPaintEvent *event)
if (text().isEmpty()) {
painter.setOpacity(1 - state_machine_->progress());
// painter.fillRect(rect(),
// parentWidget()->palette().color(backgroundRole()));
painter.fillRect(rect(), backgroundColor());
}