feat:Change pqFontPropertyWidget UI.

This commit is contained in:
sunwen
2025-06-10 16:54:58 +08:00
parent 938759f2e3
commit 7172213bf9
3 changed files with 18 additions and 354 deletions

View File

@@ -3,15 +3,6 @@
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
#include "qcolordialog.h" #include "qcolordialog.h"
//pqFontPropertyWidget* pqFontPropertyWidget::instance = nullptr;
//pqFontPropertyWidget* pqFontPropertyWidget::GetInstance() {
// //lazy man
// if (!instance) {
// instance = new pqFontPropertyWidget();
// }
// return instance;
//}
pqFontPropertyWidget* pqFontPropertyWidget::propDlg = nullptr; pqFontPropertyWidget* pqFontPropertyWidget::propDlg = nullptr;
pqFontPropertyWidget* pqFontPropertyWidget::GetPropDlg() { pqFontPropertyWidget* pqFontPropertyWidget::GetPropDlg() {
@@ -27,29 +18,9 @@ pqFontPropertyWidget::pqFontPropertyWidget(QWidget *parent)
{ {
ui.setupUi(this); ui.setupUi(this);
ui.cbx_FontFamily->addItem("Arial");
ui.cbx_FontFamily->addItem("Courier");
ui.cbx_FontFamily->addItem("Times");
connect(ui.pbtn_Accept, SIGNAL(clicked()), this, SLOT(SetTextInput())); connect(ui.pbtn_Accept, SIGNAL(clicked()), this, SLOT(SetTextInput()));
connect(ui.pbtn_Reset, SIGNAL(clicked()), this, SLOT(ResetText())); connect(ui.pbtn_Delete, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui.cbx_FontFamily, SIGNAL(currentIndexChanged(int)), this, SLOT(SetFontFamily(int)));
connect(ui.spx_FontSize, SIGNAL(valueChanged(int)), this, SLOT(SetFontSize(int)));
connect(ui.dspx_Opacity, SIGNAL(valueChanged(double)), this, SLOT(SetOpacity(double)));
connect(ui.tbtn_Bold, SIGNAL(clicked(bool)), this, SLOT(BoldOn(bool)));
connect(ui.tbnt_Italics, SIGNAL(clicked(bool)), this, SLOT(ItalicOn(bool)));
connect(ui.tbtn_Shadow, SIGNAL(clicked(bool)), this, SLOT(ShadowOn(bool)));
connect(ui.pbtn_FontColor, SIGNAL(clicked()), this, SLOT(ColorChooser()));
//connect(ui.cbx_FontColor, SIGNAL(currentIndexChanged(int)), this, SLOT(ColorEditor()));
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
//QRect rect(0, 0, 32, 26);
//QRegion region(rect, QRegion::Ellipse);
//ui.pbtn_FontColor->setMask(region);
} }
pqFontPropertyWidget::~pqFontPropertyWidget() pqFontPropertyWidget::~pqFontPropertyWidget()
@@ -57,69 +28,27 @@ pqFontPropertyWidget::~pqFontPropertyWidget()
delete propDlg; delete propDlg;
} }
void pqFontPropertyWidget::ResetText()
{
if (this->textActor)
{
this->textActor->ResetTextProp();
this->tRender->Render();
reloadProperties();
}
}
void pqFontPropertyWidget::SetTextInput() void pqFontPropertyWidget::SetTextInput()
{ {
if (this->textActor) if (this->textActor)
{ {
QString qstr = ui.led_TextInput->text(); QString qstr = ui.led_TextInput->text();
QByteArray ba = qstr.toUtf8(); if(qstr.isEmpty())
{
this->textActor->SetTextInput(ba.constData()); return;
this->tRender->Render(); }
QByteArray ba = qstr.toLatin1();
this->textActor->SetTextInput(ba.data());
this->tRender->Render();
} }
accept();
} }
void pqFontPropertyWidget::cancel()
//void pqFontPropertyWidget::ColorEditor()
//{
// if (this->textActor)
// {
// QColor color = ui.cbx_FontColor->color();
// this->textActor->GetTextPropty()->SetColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0);
// this->viewer->Render();
// }
//}
void pqFontPropertyWidget::ColorChooser()
{ {
QColor color = QColorDialog::getColor(Qt::white, this); QDialog::reject();
if (this->textActor)
{
this->textActor->GetTextProp()->SetColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0);
//ui.cbx_FontColor->setColor(color);
this->tRender->Render();
}
char str[200];
sprintf_s(str,
"background-color: rgb(%d, %d, %d);\
border-style: solid;\
border-width:2px;\
border-radius:12px;\
border-color: black;\
max-width:20px;\
max-height:20px;\
min-width:20px;\
min-height:20px;"
,color.red(), color.green(), color.blue());
ui.pbtn_FontColor->setStyleSheet(str);
} }
void pqFontPropertyWidget::SetTextActor(TextAnnotationActor* t_actor) void pqFontPropertyWidget::SetTextActor(TextAnnotationActor* t_actor)
{ {
if (this->textActor) if (this->textActor)
@@ -134,136 +63,10 @@ void pqFontPropertyWidget::SetTextActor(TextAnnotationActor* t_actor)
void pqFontPropertyWidget::SetRenderWindowInteractor(vtkRenderWindowInteractor* iren) void pqFontPropertyWidget::SetRenderWindowInteractor(vtkRenderWindowInteractor* iren)
{ {
this->tRender = iren; this->tRender = iren;
//reloadProperties();
} }
//void pqFontPropertyWidget::SetViewer(DicomImageView* v) {
// this->viewer = v;
//}
void pqFontPropertyWidget::reloadProperties() void pqFontPropertyWidget::reloadProperties()
{ {
vtkTextProperty *tprop = this->textActor->GetTextProp(); vtkTextProperty *tprop = this->textActor->GetTextProp();
//char * str = vtkTextMapper::SafeDownCast(this->textActor->GetTextProp())->GetInput();
ui.led_TextInput->setText(this->textActor->GetTextInput()); ui.led_TextInput->setText(this->textActor->GetTextInput());
ui.spx_FontSize->setValue(tprop->GetFontSize());
ui.dspx_Opacity->setValue(tprop->GetOpacity());
ui.tbtn_Bold->setChecked(tprop->GetBold());
ui.tbnt_Italics->setChecked(tprop->GetItalic());
ui.tbtn_Shadow->setChecked(tprop->GetShadow());
double *dcolor = tprop->GetColor();
QColor color(dcolor[0]*255.0, dcolor[1] * 255.0, dcolor[2] * 255.0);
char str[200];
sprintf_s(str,
"background-color: rgb(%d, %d, %d);\
border-style: solid;\
border-width:2px;\
border-radius:12px;\
border-color: black;\
max-width:20px;\
max-height:20px;\
min-width:20px;\
min-height:20px;"
, color.red(), color.green(), color.blue());
ui.pbtn_FontColor->setStyleSheet(str);
} }
void pqFontPropertyWidget::SetFontSize(int size_) {
if (this->textActor)
{
this->textActor->GetTextProp()->SetFontSize(size_);
this->tRender->Render();
}
}
void pqFontPropertyWidget::SetOpacity(double opacity_)
{
if (this->textActor)
{
this->textActor->GetTextProp()->SetOpacity(opacity_);
this->tRender->Render();
}
}
void pqFontPropertyWidget::SetFontFamily(int index)
{
if (this->textActor)
{
switch (index)
{
case(VTK_ARIAL):
this->textActor->GetTextProp()->SetFontFamilyToArial();
break;
case(VTK_COURIER):
this->textActor->GetTextProp()->SetFontFamilyToCourier();
break;
case(VTK_TIMES):
this->textActor->GetTextProp()->SetFontFamilyToTimes();
break;
default:
this->textActor->GetTextProp()->SetFontFamilyToArial();
break;
}
this->tRender->Render();
}
}
void pqFontPropertyWidget::BoldOn(bool bold_)
{
if (this->textActor)
{
if (bold_)
{
this->textActor->GetTextProp()->BoldOn();
}
else
{
this->textActor->GetTextProp()->BoldOff();
}
this->tRender->Render();
}
}
void pqFontPropertyWidget::ItalicOn(bool italic_)
{
if (this->textActor)
{
if (italic_)
{
this->textActor->GetTextProp()->ItalicOn();
}
else
{
this->textActor->GetTextProp()->ItalicOff();
}
this->tRender->Render();
}
}
void pqFontPropertyWidget::ShadowOn(bool shadow_)
{
if (this->textActor)
{
if (shadow_)
{
this->textActor->GetTextProp()->ShadowOn();
}
else
{
this->textActor->GetTextProp()->ShadowOff();
}
this->tRender->Render();
}
}

View File

@@ -21,16 +21,8 @@ public:
//void SetViewer(DicomImageView*); //void SetViewer(DicomImageView*);
void reloadProperties(); void reloadProperties();
public slots: public slots:
void SetFontSize(int);
void SetOpacity(double);
void SetFontFamily(int);
void BoldOn(bool);
void ItalicOn(bool);
void ShadowOn(bool);
//void ColorEditor();
void ColorChooser();
void SetTextInput(); void SetTextInput();
void ResetText(); void cancel();
private: private:
static pqFontPropertyWidget *propDlg; static pqFontPropertyWidget *propDlg;

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>500</width> <width>500</width>
<height>136</height> <height>79</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@@ -44,7 +44,7 @@
<string>Apply</string> <string>Apply</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../QDicomViewer.qrc"> <iconset resource="../../../../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqApply.png</normaloff>:/pqWidgets/Icon/pq/pqApply.png</iconset> <normaloff>:/pqWidgets/Icon/pq/pqApply.png</normaloff>:/pqWidgets/Icon/pq/pqApply.png</iconset>
</property> </property>
<property name="default"> <property name="default">
@@ -52,155 +52,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pbtn_Reset">
<property name="toolTip">
<string>Resets any changed properties to their values from the last time 'Apply' was clicked.</string>
</property>
<property name="text">
<string>Reset</string>
</property>
<property name="icon">
<iconset resource="../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqCancel.png</normaloff>:/pqWidgets/Icon/pq/pqCancel.png</iconset>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="pbtn_Delete"> <widget class="QPushButton" name="pbtn_Delete">
<property name="text"> <property name="text">
<string>Delete</string> <string>Cancel</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../QDicomViewer.qrc"> <iconset resource="../../../../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqDelete.png</normaloff>:/pqWidgets/Icon/pq/pqDelete.png</iconset> <normaloff>:/pqWidgets/Icon/pq/pqDelete.png</normaloff>:/pqWidgets/Icon/pq/pqDelete.png</iconset>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="cbx_FontFamily">
<property name="toolTip">
<string>Select font</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="minimumContentsLength">
<number>2</number>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spx_FontSize">
<property name="toolTip">
<string>Set font size</string>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbtn_FontColor">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="dspx_Opacity">
<property name="toolTip">
<string>Set font opacity</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbtn_Bold">
<property name="toolTip">
<string>Bold</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqBold24.png</normaloff>:/pqWidgets/Icon/pq/pqBold24.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbnt_Italics">
<property name="toolTip">
<string>Italics</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqItalics24.png</normaloff>:/pqWidgets/Icon/pq/pqItalics24.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbtn_Shadow">
<property name="toolTip">
<string>Shadow</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../QDicomViewer.qrc">
<normaloff>:/pqWidgets/Icon/pq/pqShadow24.png</normaloff>:/pqWidgets/Icon/pq/pqShadow24.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources> <resources>
<include location="../QDicomViewer.qrc"/> <include location="../../../../QDicomViewer.qrc"/>
<include location="../../../../QDicomViewer.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>