Skip to content

Commit

Permalink
Merge pull request #252 from epasveer/249-add-stack-viewer
Browse files Browse the repository at this point in the history
Use new QColorButton that has a visible frame.
  • Loading branch information
epasveer authored Oct 6, 2024
2 parents f38d77b + 54b8582 commit 4b7252a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ set(HEADER_FILES
QProcessInfoWidget.h
QProgressIndicator.h
QColorButton.h
QColorSwatch.h
QDetachTabWidget.h
QZoomChartView.h
QZoomChart.h
Expand Down Expand Up @@ -230,6 +231,7 @@ set(SOURCE_FILES
QProcessInfoWidget.cpp
QProgressIndicator.cpp
QColorButton.cpp
QColorSwatch.cpp
QDetachTabWidget.cpp
QZoomChartView.cpp
QZoomChart.cpp
Expand Down
37 changes: 15 additions & 22 deletions src/QColorButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
#include <QtGui/QPainter>
#include <QtCore/QDebug>

QColorButton::QColorButton(QWidget* parent) : QWidget(parent) {
QColorButton::QColorButton(QWidget* parent) : QFrame(parent) {

_color = palette().color(QPalette::Window);
// Construct the UI.
setupUi(this);

setColor(palette().color(QPalette::Window));
}

QColorButton::QColorButton(const QColor& color, QWidget* parent) : QWidget(parent) {
QColorButton::QColorButton(const QColor& color, QWidget* parent) : QFrame(parent) {

// Construct the UI.
setupUi(this);

_color = color;
// Create color swatch
setColor(color);
}

QColorButton::~QColorButton() {
Expand All @@ -29,31 +36,17 @@ void QColorButton::mouseDoubleClickEvent (QMouseEvent* e) {
}
}

void QColorButton::paintEvent(QPaintEvent* e) {

Q_UNUSED(e)

// Draw the color to the widget.
QPainter painter(this);

painter.setPen(Qt::NoPen);
painter.setBrush(color());
painter.drawRect(rect());
}

const QColor& QColorButton::color () {
QColor QColorButton::color () const {

// Return the current color.
return _color;
return colorSwatch->color();
}

void QColorButton::setColor (const QColor& color) {

// Save the new color.
_color = color;

// Force it to be redrawn.
update();
colorSwatch->setColor(color);
colorSwatch->update();

// Notify others that are listening.
emit colorChanged();
Expand Down
14 changes: 5 additions & 9 deletions src/QColorButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <QtGui/QMouseEvent>
#include <QtGui/QPaintEvent>
#include <QtGui/QColor>
#include <QtWidgets/QFrame>
#include <QtWidgets/QWidget>
#include "ui_QColorButton.h"

class QColorButton : public QWidget {
class QColorButton : public QFrame, protected Ui::QColorButtonForm {

Q_OBJECT

Expand All @@ -14,19 +16,13 @@ class QColorButton : public QWidget {
QColorButton(const QColor& color, QWidget* parent = 0);
~QColorButton();

void setColor (const QColor &color);
const QColor& color ();
void setColor (const QColor& color);
QColor color () const;

signals:
void colorChanged ();

protected:
void mouseDoubleClickEvent (QMouseEvent* e);
void paintEvent (QPaintEvent* e);

private slots:

private:
QColor _color;
};

50 changes: 50 additions & 0 deletions src/QColorButton.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QColorButtonForm</class>
<widget class="QFrame" name="QColorButtonForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Color Button</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QColorSwatch" name="colorSwatch" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QColorSwatch</class>
<extends>QWidget</extends>
<header location="global">QColorSwatch.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
36 changes: 36 additions & 0 deletions src/QColorSwatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "QColorSwatch.h"
#include <QtGui/QPalette>
#include <QtGui/QPainter>
#include <QtCore/QDebug>

QColorSwatch::QColorSwatch(QWidget* parent) : QWidget(parent) {
setColor(palette().color(QPalette::Window));
}

QColorSwatch::QColorSwatch(const QColor& color, QWidget* parent) : QWidget(parent) {
setColor(color);
}

QColorSwatch::~QColorSwatch() {
}

void QColorSwatch::setColor (const QColor& color) {
_color = color;
}

QColor QColorSwatch::color () const {
return _color;
}

void QColorSwatch::paintEvent(QPaintEvent* e) {

Q_UNUSED(e)

// Draw the color to the widget.
QPainter painter(this);

painter.setPen(Qt::NoPen);
painter.setBrush(color());
painter.drawRect(rect());
}

24 changes: 24 additions & 0 deletions src/QColorSwatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <QtGui/QPaintEvent>
#include <QtGui/QColor>
#include <QtWidgets/QFrame>
#include <QtWidgets/QWidget>

class QColorSwatch : public QWidget {

public:
QColorSwatch(QWidget* parent = 0);
QColorSwatch(const QColor& color, QWidget* parent = 0);
~QColorSwatch();

void setColor (const QColor& color);
QColor color () const;

protected:
void paintEvent (QPaintEvent* e);

private:
QColor _color;
};

3 changes: 3 additions & 0 deletions src/SeerStackDumpSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ SeerStackDumpSettingsDialog::SeerStackDumpSettingsDialog (QWidget* parent) : QDi
// Set up the UI.
setupUi(this);

spHighLightColorButton->setFrameStyle(QFrame::Box|QFrame::Plain);
spHighLightColorButton->setLineWidth(1);

// Setup the widgets
setStackPointerExpression("$sp");
setStackPointerColor(QColor("lightGray"));
Expand Down

0 comments on commit 4b7252a

Please sign in to comment.