add dynamic language change support
add "en" ts
This commit is contained in:
@@ -225,7 +225,7 @@ bool _DTSizeItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) {
|
||||
|
||||
|
||||
|
||||
DrawTools::DrawTools(BlockView * parent): QObject(parent),
|
||||
DrawTools::DrawTools(BlockView * parent): QWidget(parent),
|
||||
actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(this) {
|
||||
widget_props = new QWidget();
|
||||
ui = new Ui::DrawTools();
|
||||
@@ -238,9 +238,6 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
int fh = qMax<int>(QApplication::fontMetrics().size(0, "0").height(), 22);
|
||||
int thick = lineThickness();
|
||||
QSize sz(fh * 2.5, fh);
|
||||
QStringList styles;
|
||||
styles << tr("NoPen") << tr("Solid") << tr("Dash")
|
||||
<< tr("Dot") << tr("Dash-Dot") << tr("Dash-Dot-Dot");
|
||||
ui->comboLineStyle->setIconSize(sz);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
QPixmap pix(sz);
|
||||
@@ -249,7 +246,7 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
p.setPen(QPen(Qt::black, thick, (Qt::PenStyle)i));
|
||||
p.drawLine(0, pix.height() / 2, pix.width(), pix.height() / 2);
|
||||
p.end();
|
||||
ui->comboLineStyle->addItem(QIcon(pix), styles[i]);
|
||||
ui->comboLineStyle->addItem(QIcon(pix), "");
|
||||
}
|
||||
#ifdef Q_OS_MACOS
|
||||
setAlignCompact(true);
|
||||
@@ -264,22 +261,21 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
new_item = cur_item = 0;
|
||||
view_ = 0;
|
||||
resize_enabled = true;
|
||||
text_dlg.setWindowTitle(tr("Edit text"));
|
||||
text_dlg.setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
QDialogButtonBox * bbox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
connect(bbox, SIGNAL(accepted()), &text_dlg, SLOT(accept()));
|
||||
connect(bbox, SIGNAL(rejected()), &text_dlg, SLOT(reject()));
|
||||
text_dlg.layout()->addWidget(&text_edit);
|
||||
text_dlg.layout()->addWidget(bbox);
|
||||
actions_Z_up.setText(tr("Bring\nforward")); actions_Z_up.setIcon(QIcon(":/icons/z-up.png")); actions_Z_up.setEnabled(false);
|
||||
actions_Z_top.setText(tr("Bring\nto front")); actions_Z_top.setIcon(QIcon(":/icons/z-top.png")); actions_Z_top.setEnabled(false);
|
||||
actions_Z_down.setText(tr("Send\nbackward")); actions_Z_down.setIcon(QIcon(":/icons/z-down.png")); actions_Z_down.setEnabled(false);
|
||||
actions_Z_bottom.setText(tr("Send\nto back")); actions_Z_bottom.setIcon(QIcon(":/icons/z-bottom.png")); actions_Z_bottom.setEnabled(false);
|
||||
actions_add << newAction(tr("Draw\nRectangle"), QIcon(":/icons/draw-rectangle.png"), 1)
|
||||
<< newAction(tr("Draw\nEllipse"), QIcon(":/icons/draw-ellipse.png"), 2)
|
||||
<< newAction(tr("Draw\nLine"), QIcon(":/icons/draw-line.png"), 4)
|
||||
<< newAction(tr("Draw\nText"), QIcon(":/icons/draw-text.png"), 0)
|
||||
<< newAction(tr("Draw\nImage"), QIcon(":/icons/view-preview.png"), 3);
|
||||
actions_Z_up.setIcon(QIcon(":/icons/z-up.png")); actions_Z_up.setEnabled(false);
|
||||
actions_Z_top.setIcon(QIcon(":/icons/z-top.png")); actions_Z_top.setEnabled(false);
|
||||
actions_Z_down.setIcon(QIcon(":/icons/z-down.png")); actions_Z_down.setEnabled(false);
|
||||
actions_Z_bottom.setIcon(QIcon(":/icons/z-bottom.png")); actions_Z_bottom.setEnabled(false);
|
||||
actions_add << newAction(QIcon(":/icons/draw-rectangle.png"), 1)
|
||||
<< newAction(QIcon(":/icons/draw-ellipse.png"), 2)
|
||||
<< newAction(QIcon(":/icons/draw-line.png"), 4)
|
||||
<< newAction(QIcon(":/icons/draw-text.png"), 0)
|
||||
<< newAction(QIcon(":/icons/view-preview.png"), 3);
|
||||
buttons_align << ui->buttonAlignTL << ui->buttonAlignTC << ui->buttonAlignTR
|
||||
<< ui->buttonAlignCL << ui->buttonAlignCC << ui->buttonAlignCR
|
||||
<< ui->buttonAlignBL << ui->buttonAlignBC << ui->buttonAlignBR;
|
||||
@@ -321,6 +317,7 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom(
|
||||
connect(&actions_Z_down, SIGNAL(triggered(bool)), this, SLOT(actionZ_triggered()));
|
||||
connect(&actions_Z_bottom, SIGNAL(triggered(bool)), this, SLOT(actionZ_triggered()));
|
||||
setBlockView(parent);
|
||||
retranslate();
|
||||
}
|
||||
|
||||
|
||||
@@ -331,6 +328,24 @@ DrawTools::~DrawTools() {
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::retranslate() {
|
||||
QStringList styles;
|
||||
styles << tr("NoPen") << tr("Solid") << tr("Dash")
|
||||
<< tr("Dot") << tr("Dash-Dot") << tr("Dash-Dot-Dot");
|
||||
for (int i = 0; i < styles.size(); i++) ui->comboLineStyle->setItemText(i, styles[i]);
|
||||
text_dlg.setWindowTitle(tr("Edit text"));
|
||||
actions_Z_up.setText(tr("Bring\nforward"));
|
||||
actions_Z_top.setText(tr("Bring\nto front"));
|
||||
actions_Z_down.setText(tr("Send\nbackward"));
|
||||
actions_Z_bottom.setText(tr("Send\nto back"));
|
||||
actions_add[0]->setText(tr("Draw\nRectangle"));
|
||||
actions_add[1]->setText(tr("Draw\nEllipse"));
|
||||
actions_add[2]->setText(tr("Draw\nLine"));
|
||||
actions_add[3]->setText(tr("Draw\nText"));
|
||||
actions_add[4]->setText(tr("Draw\nImage"));
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::setBlockView(BlockView * v) {
|
||||
if (view_) view_->viewport()->removeEventFilter(this);
|
||||
disconnect(this, SLOT(selectionChanged()));
|
||||
@@ -454,6 +469,18 @@ bool DrawTools::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void DrawTools::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
retranslate();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QComboBox * DrawTools::textEditCombo() const {
|
||||
return ui->comboText;
|
||||
}
|
||||
@@ -468,8 +495,8 @@ void DrawTools::changeEvent(QEvent * e) {
|
||||
}
|
||||
*/
|
||||
|
||||
QAction * DrawTools::newAction(const QString & text, const QIcon & icon, int type) {
|
||||
QAction * ret = new QAction(icon, text, this);
|
||||
QAction * DrawTools::newAction(const QIcon & icon, int type) {
|
||||
QAction * ret = new QAction(icon, QString(), this);
|
||||
ret->setCheckable(true);
|
||||
ret->setData(type);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user