[TechDraw] Make icons transparent and adaptable to theme color
...and center icons
This commit is contained in:
committed by
Yorik van Havre
parent
aed7e133b0
commit
64b64b4a0b
@@ -22,11 +22,13 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <boost/algorithm/string/predicate.hpp>
|
||||
# include <QComboBox>
|
||||
# include <QGraphicsProxyWidget>
|
||||
# include <QLineEdit>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
@@ -84,7 +86,8 @@ std::string SvgString::finish()
|
||||
//===========================================================================
|
||||
|
||||
TaskSurfaceFinishSymbols::TaskSurfaceFinishSymbols(const std::string &ownerName) :
|
||||
ui(new Ui_TaskSurfaceFinishSymbols)
|
||||
ui(new Ui_TaskSurfaceFinishSymbols),
|
||||
currentIcon(nullptr)
|
||||
{
|
||||
App::Document *doc = App::GetApplication().getActiveDocument();
|
||||
if (doc) {
|
||||
@@ -141,26 +144,39 @@ TaskSurfaceFinishSymbols::TaskSurfaceFinishSymbols(const std::string &ownerName)
|
||||
setUiEdit();
|
||||
}
|
||||
|
||||
QColor TaskSurfaceFinishSymbols::getPenColor()
|
||||
{
|
||||
// TODO: should be dependent on global API giving pen color - not from hacking stylesheet name
|
||||
const std::string stylesheetName = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/MainWindow")->GetASCII("StyleSheet");
|
||||
if(boost::icontains(stylesheetName, "dark")) {
|
||||
return Qt::white;
|
||||
}
|
||||
return Qt::black;
|
||||
}
|
||||
|
||||
QPixmap TaskSurfaceFinishSymbols::baseSymbol(symbolType type)
|
||||
// return QPixmap showing a base symbol
|
||||
{
|
||||
QImage img (50, 64, QImage::Format_ARGB32_Premultiplied);
|
||||
img.fill(QColor(240, 240, 240));
|
||||
img.fill(Qt::transparent);
|
||||
|
||||
// TODO: color should depend on theme/background
|
||||
QPainter painter;
|
||||
painter.begin(&img);
|
||||
painter.setPen(QPen(Qt::black, 2, Qt::SolidLine,
|
||||
painter.setPen(QPen(getPenColor(), 2, Qt::SolidLine,
|
||||
Qt::RoundCap, Qt::RoundJoin));
|
||||
painter.setRenderHints(QPainter::Antialiasing |
|
||||
QPainter::SmoothPixmapTransform |
|
||||
QPainter::TextAntialiasing);
|
||||
painter.drawLine(QLine(0, 44, 12, 64));
|
||||
painter.drawLine(QLine(12, 64, 42, 14));
|
||||
painter.drawLine(QLine(0, 40, 12, 60));
|
||||
painter.drawLine(QLine(12, 60, 42, 10));
|
||||
if (type == removeProhibit || type == removeProhibitAll)
|
||||
painter.drawEllipse(QPoint(12, 46), 9,9);
|
||||
painter.drawEllipse(QPoint(12, 42), 9,9);
|
||||
if (type == removeRequired || type == removeRequiredAll)
|
||||
painter.drawLine(QLine(0, 44, 24, 44));
|
||||
painter.drawLine(QLine(0, 40, 24, 40));
|
||||
if (type > removeRequired)
|
||||
painter.drawEllipse(QPoint(42, 14), 6,6);
|
||||
painter.drawEllipse(QPoint(42, 10), 6,6);
|
||||
painter.end();
|
||||
return QPixmap::fromImage(img);
|
||||
}
|
||||
@@ -251,7 +267,9 @@ void TaskSurfaceFinishSymbols::setUiEdit()
|
||||
|
||||
// Create scene and all items used in the scene
|
||||
symbolScene = new(QGraphicsScene);
|
||||
ui->graphicsView->setBackgroundBrush(Qt::NoBrush);
|
||||
ui->graphicsView->setScene(symbolScene);
|
||||
|
||||
// QLineEdit showing method
|
||||
leMethod = new(QLineEdit);
|
||||
leMethod->resize(90, 20);
|
||||
@@ -310,15 +328,8 @@ void TaskSurfaceFinishSymbols::setUiEdit()
|
||||
proxyMaxRough->hide();
|
||||
// add horizontal line
|
||||
symbolScene->addLine(QLine(-8, -116, 90, -116),
|
||||
QPen(Qt::black, 2,Qt::SolidLine,
|
||||
QPen(getPenColor(), 2,Qt::SolidLine,
|
||||
Qt::RoundCap, Qt::RoundJoin));
|
||||
// add pixmap of the surface finish symbol
|
||||
QIcon symbolIcon = ui->pbIcon01->icon();
|
||||
QGraphicsPixmapItem* pixmapItem = new(QGraphicsPixmapItem);
|
||||
pixmapItem->setPixmap(symbolIcon.pixmap(50, 64));
|
||||
pixmapItem->setPos(-50, -130);
|
||||
pixmapItem->setZValue(-1);
|
||||
symbolScene->addItem(pixmapItem);
|
||||
|
||||
connect(ui->pbIcon01, &QPushButton::clicked, this, &TaskSurfaceFinishSymbols::onIconChanged);
|
||||
connect(ui->pbIcon02, &QPushButton::clicked, this, &TaskSurfaceFinishSymbols::onIconChanged);
|
||||
@@ -328,6 +339,9 @@ void TaskSurfaceFinishSymbols::setUiEdit()
|
||||
connect(ui->pbIcon06, &QPushButton::clicked, this, &TaskSurfaceFinishSymbols::onIconChanged);
|
||||
connect(ui->rbISO, &QPushButton::clicked, this, &TaskSurfaceFinishSymbols::onISO);
|
||||
connect(ui->rbASME, &QPushButton::clicked, this, &TaskSurfaceFinishSymbols::onASME);
|
||||
|
||||
// set initial icon
|
||||
ui->pbIcon01->click();
|
||||
}
|
||||
|
||||
void TaskSurfaceFinishSymbols::onIconChanged()
|
||||
@@ -347,11 +361,14 @@ void TaskSurfaceFinishSymbols::onIconChanged()
|
||||
if (ui->pbIcon06 == pressedButton) activeIcon = removeRequiredAll;
|
||||
|
||||
QIcon symbolIcon = pressedButton->icon();
|
||||
QGraphicsPixmapItem* pixmapItem = new(QGraphicsPixmapItem);
|
||||
pixmapItem->setPixmap(symbolIcon.pixmap(50, 64));
|
||||
pixmapItem->setPos(-50, -130);
|
||||
pixmapItem->setZValue(-1);
|
||||
symbolScene->addItem(pixmapItem);
|
||||
if(currentIcon) {
|
||||
symbolScene->removeItem(currentIcon);
|
||||
}
|
||||
currentIcon = new(QGraphicsPixmapItem);
|
||||
currentIcon->setPixmap(symbolIcon.pixmap(50, 64));
|
||||
currentIcon->setPos(-50, -126);
|
||||
currentIcon->setZValue(-1);
|
||||
symbolScene->addItem(currentIcon);
|
||||
}
|
||||
|
||||
void TaskSurfaceFinishSymbols::onISO()
|
||||
|
||||
@@ -105,7 +105,9 @@ private:
|
||||
QComboBox *cbRA, *cbMinRought, *cbMaxRought, *cbLay;
|
||||
symbolType activeIcon;
|
||||
bool isISO;
|
||||
QGraphicsPixmapItem* currentIcon;
|
||||
std::unique_ptr<Ui_TaskSurfaceFinishSymbols> ui;
|
||||
QColor getPenColor();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onIconChanged();
|
||||
|
||||
@@ -310,15 +310,6 @@
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="backgroundBrush">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>240</red>
|
||||
<green>240</green>
|
||||
<blue>240</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</property>
|
||||
<property name="sceneRect">
|
||||
<rectf>
|
||||
<x>0.000000000000000</x>
|
||||
|
||||
Reference in New Issue
Block a user