viewertexteditor: rearranged toolbar, added valign buttons

This commit is contained in:
itsmattkc
2022-08-24 14:14:50 -07:00
parent a0f11472ac
commit 3dfaf807af
6 changed files with 159 additions and 102 deletions
+2 -2
View File
@@ -142,7 +142,7 @@ void Html::WriteBlock(QXmlStreamWriter *writer, const QTextBlock &block)
if (!(fmt.alignment() & Qt::AlignLeft)) {
if (fmt.alignment() & Qt::AlignRight) {
writer->writeAttribute(QStringLiteral("align"), QStringLiteral("right"));
} else if (fmt.alignment() & Qt::AlignCenter) {
} else if (fmt.alignment() & Qt::AlignHCenter) {
writer->writeAttribute(QStringLiteral("align"), QStringLiteral("center"));
} else if (fmt.alignment() & Qt::AlignJustify) {
writer->writeAttribute(QStringLiteral("align"), QStringLiteral("justify"));
@@ -369,7 +369,7 @@ QTextBlockFormat Html::ReadBlockFormat(const QXmlStreamAttributes &attributes)
if (StrEquals(attr.value(), QStringLiteral("right"))) {
block_fmt.setAlignment(Qt::AlignRight);
} else if (StrEquals(attr.value(), QStringLiteral("center"))) {
block_fmt.setAlignment(Qt::AlignCenter);
block_fmt.setAlignment(Qt::AlignHCenter);
} else if (StrEquals(attr.value(), QStringLiteral("justify"))) {
block_fmt.setAlignment(Qt::AlignJustify);
}
+1 -1
View File
@@ -43,7 +43,7 @@ QFrame *QtUtils::CreateHorizontalLine()
QFrame *QtUtils::CreateVerticalLine()
{
QFrame *l = CreateHorizontalLine();
l->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
l->setFrameShape(QFrame::VLine);
return l;
}
+6
View File
@@ -75,6 +75,9 @@ QIcon icon::TextAlignLeft;
QIcon icon::TextAlignRight;
QIcon icon::TextAlignCenter;
QIcon icon::TextAlignJustify;
QIcon icon::TextAlignTop;
QIcon icon::TextAlignBottom;
QIcon icon::TextAlignMiddle;
QIcon icon::Snapping;
QIcon icon::ZoomIn;
QIcon icon::ZoomOut;
@@ -145,6 +148,9 @@ void icon::LoadAll(const QString& theme)
TextAlignRight = Create(theme, "align-right");
TextAlignCenter = Create(theme, "align-center");
TextAlignJustify = Create(theme, "align-justify-all");
TextAlignTop = Create(theme, "align-left");
TextAlignBottom = Create(theme, "align-right");
TextAlignMiddle = Create(theme, "align-center");
Snapping = Create(theme, "magnet");
ZoomIn = Create(theme, "zoomin");
+3
View File
@@ -85,6 +85,9 @@ extern QIcon TextAlignLeft;
extern QIcon TextAlignRight;
extern QIcon TextAlignCenter;
extern QIcon TextAlignJustify;
extern QIcon TextAlignTop;
extern QIcon TextAlignBottom;
extern QIcon TextAlignMiddle;
// Miscellaneous Icons
extern QIcon Snapping;
+140 -99
View File
@@ -313,129 +313,156 @@ ViewerTextEditorToolBar::ViewerTextEditorToolBar(QWidget *parent) :
drag_enabled_(false)
{
QVBoxLayout *outer_layout = new QVBoxLayout(this);
outer_layout->setSpacing(0);
QHBoxLayout *basic_layout = new QHBoxLayout();
outer_layout->addLayout(basic_layout);
const int advanced_slider_width = QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral("9999.9%"));
int advanced_slider_width = QtUtils::QFontMetricsWidth(fontMetrics(), QStringLiteral("9999.9%"));
{
QHBoxLayout *row_layout = new QHBoxLayout();
row_layout->setSpacing(0);
outer_layout->addLayout(row_layout);
font_combo_ = new QFontComboBox();
connect(font_combo_, &QFontComboBox::currentTextChanged, this, &ViewerTextEditorToolBar::UpdateFontStyleListAndEmitFamilyChanged);
basic_layout->addWidget(font_combo_);
font_combo_ = new QFontComboBox();
connect(font_combo_, &QFontComboBox::currentTextChanged, this, &ViewerTextEditorToolBar::UpdateFontStyleListAndEmitFamilyChanged);
row_layout->addWidget(font_combo_);
font_sz_slider_ = new FloatSlider();
font_sz_slider_->SetMinimum(0.1);
font_sz_slider_->SetMaximum(9999.9);
font_sz_slider_->SetDecimalPlaces(1);
font_sz_slider_->SetAlignment(Qt::AlignCenter);
font_sz_slider_->setFixedWidth(advanced_slider_width);
connect(font_sz_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::SizeChanged);
font_sz_slider_->SetLadderElementCount(2);
basic_layout->addWidget(font_sz_slider_);
font_sz_slider_ = new FloatSlider();
font_sz_slider_->SetMinimum(0.1);
font_sz_slider_->SetMaximum(9999.9);
font_sz_slider_->SetDecimalPlaces(1);
font_sz_slider_->SetAlignment(Qt::AlignCenter);
font_sz_slider_->setFixedWidth(advanced_slider_width);
connect(font_sz_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::SizeChanged);
font_sz_slider_->SetLadderElementCount(2);
row_layout->addWidget(font_sz_slider_);
style_combo_ = new QComboBox();
connect(style_combo_, &QComboBox::currentTextChanged, this, &ViewerTextEditorToolBar::StyleChanged);
basic_layout->addWidget(style_combo_);
style_combo_ = new QComboBox();
connect(style_combo_, &QComboBox::currentTextChanged, this, &ViewerTextEditorToolBar::StyleChanged);
row_layout->addWidget(style_combo_);
underline_btn_ = new QPushButton();
connect(underline_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::UnderlineChanged);
underline_btn_->setCheckable(true);
underline_btn_->setIcon(icon::TextUnderline);
basic_layout->addWidget(underline_btn_);
underline_btn_ = new QPushButton();
connect(underline_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::UnderlineChanged);
underline_btn_->setCheckable(true);
underline_btn_->setIcon(icon::TextUnderline);
row_layout->addWidget(underline_btn_);
strikethrough_btn_ = new QPushButton();
connect(strikethrough_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::StrikethroughChanged);
strikethrough_btn_->setCheckable(true);
strikethrough_btn_->setIcon(icon::TextStrikethrough);
basic_layout->addWidget(strikethrough_btn_);
strikethrough_btn_ = new QPushButton();
connect(strikethrough_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::StrikethroughChanged);
strikethrough_btn_->setCheckable(true);
strikethrough_btn_->setIcon(icon::TextStrikethrough);
row_layout->addWidget(strikethrough_btn_);
basic_layout->addWidget(QtUtils::CreateVerticalLine());
AddSpacer(row_layout);
align_left_btn_ = new QPushButton();
align_left_btn_->setCheckable(true);
align_left_btn_->setIcon(icon::TextAlignLeft);
connect(align_left_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignLeft);});
basic_layout->addWidget(align_left_btn_);
color_btn_ = new QPushButton();
color_btn_->setAutoFillBackground(true);
connect(color_btn_, &QPushButton::clicked, this, [this]{
QColor c = color_btn_->property("color").value<QColor>();
align_center_btn_ = new QPushButton();
align_center_btn_->setCheckable(true);
align_center_btn_->setIcon(icon::TextAlignCenter);
connect(align_center_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignCenter);});
basic_layout->addWidget(align_center_btn_);
QColorDialog cd(c, this);
if (cd.exec() == QDialog::Accepted) {
c = cd.selectedColor();
SetColor(c);
emit ColorChanged(c);
}
});
row_layout->addWidget(color_btn_);
align_right_btn_ = new QPushButton();
align_right_btn_->setCheckable(true);
align_right_btn_->setIcon(icon::TextAlignRight);
connect(align_right_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignRight);});
basic_layout->addWidget(align_right_btn_);
row_layout->addStretch();
}
align_justify_btn_ = new QPushButton();
align_justify_btn_->setCheckable(true);
align_justify_btn_->setIcon(icon::TextAlignJustify);
connect(align_justify_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignJustify);});
basic_layout->addWidget(align_justify_btn_);
{
QHBoxLayout *row_layout = new QHBoxLayout();
row_layout->setSpacing(0);
outer_layout->addLayout(row_layout);
basic_layout->addWidget(QtUtils::CreateVerticalLine());
align_left_btn_ = new QPushButton();
align_left_btn_->setCheckable(true);
align_left_btn_->setIcon(icon::TextAlignLeft);
connect(align_left_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignLeft);});
row_layout->addWidget(align_left_btn_);
color_btn_ = new QPushButton();
color_btn_->setAutoFillBackground(true);
connect(color_btn_, &QPushButton::clicked, this, [this]{
QColor c = color_btn_->property("color").value<QColor>();
align_center_btn_ = new QPushButton();
align_center_btn_->setCheckable(true);
align_center_btn_->setIcon(icon::TextAlignCenter);
connect(align_center_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignHCenter);});
row_layout->addWidget(align_center_btn_);
QColorDialog cd(c, this);
if (cd.exec() == QDialog::Accepted) {
c = cd.selectedColor();
SetColor(c);
emit ColorChanged(c);
}
});
basic_layout->addWidget(color_btn_);
align_right_btn_ = new QPushButton();
align_right_btn_->setCheckable(true);
align_right_btn_->setIcon(icon::TextAlignRight);
connect(align_right_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignRight);});
row_layout->addWidget(align_right_btn_);
basic_layout->addStretch();
align_justify_btn_ = new QPushButton();
align_justify_btn_->setCheckable(true);
align_justify_btn_->setIcon(icon::TextAlignJustify);
connect(align_justify_btn_, &QPushButton::clicked, this, [this]{emit AlignmentChanged(Qt::AlignJustify);});
row_layout->addWidget(align_justify_btn_);
QHBoxLayout *advanced_layout = new QHBoxLayout();
outer_layout->addLayout(advanced_layout);
AddSpacer(row_layout);
advanced_layout->addWidget(new QLabel(tr("Stretch: "))); // FIXME: Procure icon
align_top_btn_ = new QPushButton();
align_top_btn_->setCheckable(true);
align_top_btn_->setIcon(icon::TextAlignTop);
connect(align_top_btn_, &QPushButton::clicked, this, [this]{emit VerticalAlignmentChanged(Qt::AlignTop);});
row_layout->addWidget(align_top_btn_);
stretch_slider_ = new IntegerSlider();
stretch_slider_->SetMinimum(0);
stretch_slider_->SetDefaultValue(100);
stretch_slider_->setFixedWidth(advanced_slider_width);
stretch_slider_->SetFormat(tr("%1%"));
connect(stretch_slider_, &IntegerSlider::ValueChanged, this, &ViewerTextEditorToolBar::StretchChanged);
advanced_layout->addWidget(stretch_slider_);
align_middle_btn_ = new QPushButton();
align_middle_btn_->setCheckable(true);
align_middle_btn_->setIcon(icon::TextAlignMiddle);
connect(align_middle_btn_, &QPushButton::clicked, this, [this]{emit VerticalAlignmentChanged(Qt::AlignVCenter);});
row_layout->addWidget(align_middle_btn_);
advanced_layout->addWidget(new QLabel(tr("Kerning: "))); // FIXME: Procure icon
align_bottom_btn_ = new QPushButton();
align_bottom_btn_->setCheckable(true);
align_bottom_btn_->setIcon(icon::TextAlignBottom);
connect(align_bottom_btn_, &QPushButton::clicked, this, [this]{emit VerticalAlignmentChanged(Qt::AlignBottom);});
row_layout->addWidget(align_bottom_btn_);
kerning_slider_ = new FloatSlider();
kerning_slider_->SetMinimum(0);
kerning_slider_->SetDefaultValue(100);
kerning_slider_->SetDecimalPlaces(1);
kerning_slider_->setFixedWidth(advanced_slider_width);
kerning_slider_->SetFormat(tr("%1%"));
connect(kerning_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::KerningChanged);
advanced_layout->addWidget(kerning_slider_);
AddSpacer(row_layout);
advanced_layout->addWidget(new QLabel(tr("Line Height: "))); // FIXME: Procure icon
small_caps_btn_ = new QPushButton();
small_caps_btn_->setIcon(icon::TextSmallCaps);
small_caps_btn_->setCheckable(true);
connect(small_caps_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::SmallCapsChanged);
row_layout->addWidget(small_caps_btn_);
line_height_slider_ = new FloatSlider();
line_height_slider_->SetMinimum(0);
line_height_slider_->SetDefaultValue(100);
line_height_slider_->SetDecimalPlaces(1);
line_height_slider_->setFixedWidth(advanced_slider_width);
line_height_slider_->SetFormat(tr("%1%"));
connect(line_height_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::LineHeightChanged);
advanced_layout->addWidget(line_height_slider_);
AddSpacer(row_layout);
small_caps_btn_ = new QPushButton();
small_caps_btn_->setIcon(icon::TextSmallCaps);
small_caps_btn_->setCheckable(true);
connect(small_caps_btn_, &QPushButton::clicked, this, &ViewerTextEditorToolBar::SmallCapsChanged);
advanced_layout->addWidget(small_caps_btn_);
row_layout->addWidget(new QLabel(tr("Stretch: "))); // FIXME: Procure icon
advanced_layout->addStretch();
stretch_slider_ = new IntegerSlider();
stretch_slider_->SetMinimum(0);
stretch_slider_->SetDefaultValue(100);
stretch_slider_->setFixedWidth(advanced_slider_width);
stretch_slider_->SetFormat(tr("%1%"));
connect(stretch_slider_, &IntegerSlider::ValueChanged, this, &ViewerTextEditorToolBar::StretchChanged);
row_layout->addWidget(stretch_slider_);
row_layout->addWidget(new QLabel(tr("Kerning: "))); // FIXME: Procure icon
kerning_slider_ = new FloatSlider();
kerning_slider_->SetMinimum(0);
kerning_slider_->SetDefaultValue(100);
kerning_slider_->SetDecimalPlaces(1);
kerning_slider_->setFixedWidth(advanced_slider_width);
kerning_slider_->SetFormat(tr("%1%"));
connect(kerning_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::KerningChanged);
row_layout->addWidget(kerning_slider_);
row_layout->addWidget(new QLabel(tr("Line Height: "))); // FIXME: Procure icon
line_height_slider_ = new FloatSlider();
line_height_slider_->SetMinimum(0);
line_height_slider_->SetDefaultValue(100);
line_height_slider_->SetDecimalPlaces(1);
line_height_slider_->setFixedWidth(advanced_slider_width);
line_height_slider_->SetFormat(tr("%1%"));
connect(line_height_slider_, &FloatSlider::ValueChanged, this, &ViewerTextEditorToolBar::LineHeightChanged);
row_layout->addWidget(line_height_slider_);
row_layout->addStretch();
}
setAutoFillBackground(true);
@@ -445,7 +472,7 @@ ViewerTextEditorToolBar::ViewerTextEditorToolBar(QWidget *parent) :
void ViewerTextEditorToolBar::SetAlignment(Qt::Alignment a)
{
align_left_btn_->setChecked(a == Qt::AlignLeft);
align_center_btn_->setChecked(a == Qt::AlignCenter);
align_center_btn_->setChecked(a == Qt::AlignHCenter);
align_right_btn_->setChecked(a == Qt::AlignRight);
align_justify_btn_->setChecked(a == Qt::AlignJustify);
}
@@ -470,6 +497,20 @@ void ViewerTextEditorToolBar::paintEvent(QPaintEvent *event)
QWidget::paintEvent(event);
}
void ViewerTextEditorToolBar::AddSpacer(QLayout *l)
{
const int spacing = this->fontMetrics().height()/4;
QWidget *a = new QWidget();
a->setFixedSize(spacing, 1);
l->addWidget(a);
l->addWidget(QtUtils::CreateVerticalLine());
QWidget *b = new QWidget();
b->setFixedSize(spacing, 1);
l->addWidget(b);
}
void ViewerTextEditorToolBar::UpdateFontStyleList(const QString &family)
{
QString temp = style_combo_->currentText();
+7
View File
@@ -81,6 +81,7 @@ signals:
void UnderlineChanged(bool e);
void StrikethroughChanged(bool e);
void AlignmentChanged(Qt::Alignment alignment);
void VerticalAlignmentChanged(Qt::Alignment alignment);
void ColorChanged(const QColor &c);
void SmallCapsChanged(bool e);
void StretchChanged(int i);
@@ -101,6 +102,8 @@ protected:
virtual void paintEvent(QPaintEvent *event) override;
private:
void AddSpacer(QLayout *l);
QPoint drag_anchor_;
QFontComboBox *font_combo_;
@@ -117,6 +120,10 @@ private:
QPushButton *align_right_btn_;
QPushButton *align_justify_btn_;
QPushButton *align_top_btn_;
QPushButton *align_middle_btn_;
QPushButton *align_bottom_btn_;
IntegerSlider *stretch_slider_;
FloatSlider *kerning_slider_;
FloatSlider *line_height_slider_;