Use KDAB artwork for the dockwidgets example
Work in progress but already looks good.
This commit is contained in:
@@ -20,39 +20,80 @@
|
||||
|
||||
#include "MyWidget.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QRadioButton>
|
||||
#include <QPushButton>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
MyWidget::MyWidget(QWidget *parent)
|
||||
MyWidget::MyWidget(const QString &backgroundFile, const QString &logoFile, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_background(QImage(backgroundFile))
|
||||
, m_logo(QImage(logoFile))
|
||||
{
|
||||
auto l = new QVBoxLayout(this);
|
||||
|
||||
auto box = new QGroupBox();
|
||||
auto l2 = new QVBoxLayout(box);
|
||||
auto radio1 = new QRadioButton(QStringLiteral("foo"), box);
|
||||
auto radio2 = new QRadioButton(QStringLiteral("bar"), box);
|
||||
auto radio3 = new QRadioButton(QStringLiteral("baz"), box);
|
||||
l2->addWidget(radio1);
|
||||
l2->addWidget(radio2);
|
||||
l2->addWidget(radio3);
|
||||
|
||||
l->addWidget(box);
|
||||
auto button = new QPushButton(QStringLiteral("Test"));
|
||||
l->addWidget(button);
|
||||
l->addWidget(new QPushButton(QStringLiteral("Test")));
|
||||
l->addStretch();
|
||||
|
||||
connect(button, &QPushButton::clicked, button, [this] {
|
||||
// To test if moving windows work on Wayland
|
||||
QPoint pos = window()->pos();
|
||||
window()->move(pos + QPoint(30, 30));
|
||||
});
|
||||
if (!backgroundFile.isEmpty() && m_background.isNull())
|
||||
qWarning() << "Invalid image for background file" << backgroundFile;
|
||||
|
||||
if (!logoFile.isEmpty() && m_logo.isNull())
|
||||
qWarning() << "Invalid image for logo file" << logoFile;
|
||||
}
|
||||
|
||||
MyWidget::~MyWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void MyWidget::drawLogo(QPainter &p)
|
||||
{
|
||||
if (m_logo.isNull())
|
||||
return;
|
||||
|
||||
const qreal ratio = m_logo.width() / (m_logo.height() * 1.0);
|
||||
|
||||
const int height = size().height() - 100;
|
||||
const int width = int(height * ratio);
|
||||
QRect targetLogoRect(0,0, width, height);
|
||||
targetLogoRect.moveCenter(rect().center());
|
||||
p.drawImage(targetLogoRect, m_logo, m_logo.rect());
|
||||
}
|
||||
|
||||
MyWidget1::MyWidget1(MyWidget::QWidget *parent)
|
||||
: MyWidget(QStringLiteral(":/assets/triangles.png"), QStringLiteral(":/assets/KDAB_bubble_white.png"), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MyWidget1::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.fillRect(rect(), QColor(0xCC, 0xCC, 0xCC));
|
||||
p.drawImage(m_background.rect(), m_background, m_background.rect());
|
||||
|
||||
drawLogo(p);
|
||||
}
|
||||
|
||||
MyWidget2::MyWidget2(MyWidget::QWidget *parent)
|
||||
: MyWidget(QString(), QStringLiteral(":/assets/KDAB_bubble_blue.png"), parent)
|
||||
, m_triangle(QImage(QStringLiteral(":/assets/tri.png")))
|
||||
{
|
||||
}
|
||||
|
||||
void MyWidget2::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.fillRect(rect(), Qt::white);
|
||||
|
||||
//.drawImage(rect(), m_triangle, m_triangle.rect());
|
||||
|
||||
drawLogo(p);
|
||||
}
|
||||
|
||||
MyWidget3::MyWidget3(MyWidget::QWidget *parent)
|
||||
: MyWidget(QStringLiteral(":/assets/base.png"), QStringLiteral(":/assets/KDAB_bubble_fulcolor.png"), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void MyWidget3::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter p(this);
|
||||
p.fillRect(rect(), QColor(0xD5, 0xD5, 0xD5));
|
||||
|
||||
p.drawImage(m_background.rect(), m_background, m_background.rect());
|
||||
drawLogo(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user