[qet] qet/qet: [5766] Independent text can have custom font.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5766
Author:   blacksun
Date:     2019-03-08 14:47:33 +0100 (Fri, 08 Mar 2019)
Log Message:
-----------
Independent text can have custom font.

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/independenttextitem.cpp
    trunk/sources/ui/inditextpropertieswidget.cpp
    trunk/sources/ui/inditextpropertieswidget.h
    trunk/sources/ui/inditextpropertieswidget.ui

Modified: trunk/sources/qetgraphicsitem/independenttextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/independenttextitem.cpp	2019-03-08 11:53:27 UTC (rev 5765)
+++ trunk/sources/qetgraphicsitem/independenttextitem.cpp	2019-03-08 13:47:33 UTC (rev 5766)
@@ -52,6 +52,12 @@
 	setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
 	setHtml(e.attribute("text"));
 	setRotation(e.attribute("rotation").toDouble());
+	if (e.hasAttribute("font"))
+	{
+		QFont font;
+		font.fromString(e.attribute("font"));
+		setFont(font);
+	}
 }
 
 /**
@@ -65,6 +71,7 @@
 	result.setAttribute("y", QString("%1").arg(pos().y()));
 	result.setAttribute("text", toHtml());
 	result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
+	result.setAttribute("font", font().toString());
 	
 	return(result);
 }

Modified: trunk/sources/ui/inditextpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.cpp	2019-03-08 11:53:27 UTC (rev 5765)
+++ trunk/sources/ui/inditextpropertieswidget.cpp	2019-03-08 13:47:33 UTC (rev 5766)
@@ -198,6 +198,11 @@
 				undo = new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), font);
 				undo->setText(tr("Modifier la taille d'un champ texte"));
 			}
+			if (m_font_is_selected &&
+				m_selected_font != m_text->font()) {
+				undo = new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), m_selected_font);
+				undo->setText(tr("Modifier la police d'un champ texte"));
+			}
 			
 			return undo;
 		}
@@ -206,8 +211,10 @@
 			QUndoCommand *parent_undo = nullptr;
 			bool size_equal = true;
 			bool angle_equal = true;
+			bool font_equal = true;
 			qreal rotation_ = m_text_list.first()->rotation();
 			int size_ = m_text_list.first()->font().pointSize();
+			QFont font_ = m_text_list.first()->font();
 			for (QPointer<IndependentTextItem> piti : m_text_list)
 			{
 				if (piti->rotation() != rotation_) {
@@ -216,6 +223,9 @@
 				if (piti->font().pointSize() != size_) {
 					size_equal = false;
 				}
+				if (piti->font() != font_) {
+					font_equal = false;
+				}
 			}
 				
 			if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) ||
@@ -245,11 +255,24 @@
 						}
 						QFont font = piti->font();
 						font.setPointSize(ui->m_size_sb->value());
-						QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "font", QVariant(piti->font()), QVariant(font), parent_undo);
-						qpuc->setAnimated(true, false);
+						new QPropertyUndoCommand(piti.data(), "font", QVariant(piti->font()), QVariant(font), parent_undo);
 					}
 				}
 			}
+			else if ((m_font_is_selected && !font_equal) ||
+					 (m_font_is_selected && (font_equal && (m_selected_font != font_))))
+			{
+				for (QPointer<IndependentTextItem> piti : m_text_list)
+				{
+					if (piti)
+					{
+						if (!parent_undo) {
+							parent_undo = new QUndoCommand(tr("Modifier la police de plusieurs champs texte"));
+						}
+						new QPropertyUndoCommand(piti.data(), "font", piti->font(), m_selected_font, parent_undo);
+					}
+				}
+			}
 			return parent_undo;
 		}
 	}
@@ -275,6 +298,9 @@
 			font.setPointSize(ui->m_size_sb->value());
 			new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), font, undo);
 		}
+		if (m_font_is_selected && m_selected_font != m_text->font()) {
+			new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), m_selected_font, undo);
+		}
 		
 		if (undo->childCount()) {
 			return undo;
@@ -305,7 +331,11 @@
 		m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply);
 	}
 	m_edit_connection << connect(ui->m_angle_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
-	m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
+	m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
+	{
+		this->m_selected_font.setPointSize(ui->m_size_sb->value());
+		this->apply();
+	});
 }
 
 /**
@@ -341,13 +371,18 @@
 		ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false);
 		ui->m_label->setVisible(m_text->isHtml() ? true : false);
 		ui->m_break_html_pb->setVisible(m_text->isHtml() ? true : false);
+		ui->m_font_pb->setDisabled(m_text->isHtml() ? true : false);
+		ui->m_font_pb->setText(m_text->isHtml() ? tr("Police") : m_text->font().family());
 	}
 	else
 	{
 		bool size_equal = true;
 		bool angle_equal = true;
+		bool font_equal = true;
 		qreal rotation_ = m_text_list.first()->rotation();
 		int size_ = m_text_list.first()->font().pointSize();
+		QFont font_ = m_text_list.first()->font();
+
 		for (QPointer<IndependentTextItem> piti : m_text_list)
 		{
 			if (piti->rotation() != rotation_) {
@@ -356,6 +391,9 @@
 			if (piti->font().pointSize() != size_) {
 				size_equal = false;
 			}
+			if (piti->font() != font_) {
+				font_equal = false;
+			}
 		}
 		ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0);
 		
@@ -365,6 +403,8 @@
 				valid_ = false;
 			}
 		}
+		ui->m_font_pb->setEnabled(valid_);
+		ui->m_font_pb->setText(font_equal ? font_.family() : tr("Police"));
 		ui->m_size_sb->setEnabled(valid_);
 		ui->m_size_sb->setValue(size_equal ? size_ : 0);
 		ui->m_label->setVisible(false);
@@ -396,3 +436,22 @@
 	
 	updateUi();
 }
+
+void IndiTextPropertiesWidget::on_m_font_pb_clicked()
+{
+	if (!m_text && m_text_list.isEmpty()) {
+		return;
+	}
+	bool ok;
+	QFont font = m_text ? m_text->font() : m_text_list.first()->font();
+	m_selected_font = QFontDialog::getFont(&ok, font, this);
+	if (ok) {
+		m_font_is_selected = true;
+		ui->m_font_pb->setText(font.family());
+		ui->m_size_sb->setValue(font.pointSize());
+		apply();
+	} else {
+		ui->m_font_pb->setText(tr("Police"));
+		m_font_is_selected = false;
+	}
+}

Modified: trunk/sources/ui/inditextpropertieswidget.h
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.h	2019-03-08 11:53:27 UTC (rev 5765)
+++ trunk/sources/ui/inditextpropertieswidget.h	2019-03-08 13:47:33 UTC (rev 5766)
@@ -48,8 +48,9 @@
 	private slots:
 		void on_m_advanced_editor_pb_clicked();	
 		void on_m_break_html_pb_clicked();
-		
-	private:
+		void on_m_font_pb_clicked();
+
+		private:
 		void setUpEditConnection();
 		void updateUi() override;
 		
@@ -59,6 +60,8 @@
 		QList <QPointer<IndependentTextItem>> m_text_list;
 		QList <QMetaObject::Connection> m_connect_list,
 										m_edit_connection;
+		QFont m_selected_font;
+		bool m_font_is_selected = false;
 };
 
 #endif // INDITEXTPROPERTIESWIDGET_H

Modified: trunk/sources/ui/inditextpropertieswidget.ui
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.ui	2019-03-08 11:53:27 UTC (rev 5765)
+++ trunk/sources/ui/inditextpropertieswidget.ui	2019-03-08 13:47:33 UTC (rev 5766)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>288</width>
-    <height>251</height>
+    <width>340</width>
+    <height>296</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -126,17 +126,10 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="0" colspan="4">
-    <widget class="QLineEdit" name="m_line_edit">
-     <property name="placeholderText">
-      <string>Texte</string>
-     </property>
-    </widget>
-   </item>
    <item row="4" column="0" colspan="4">
     <widget class="QLabel" name="m_label">
      <property name="text">
-      <string>Le contenu et la taille du texte ne peuvent être modifié car formaté en html.
+      <string>Le contenu, la taille et la police du texte ne peuvent être modifié car formaté en html.
 Veuillez utiliser l'éditeur avancé pour cela.</string>
      </property>
      <property name="scaledContents">
@@ -154,6 +147,20 @@
      </property>
     </widget>
    </item>
+   <item row="0" column="0" colspan="3">
+    <widget class="QLineEdit" name="m_line_edit">
+     <property name="placeholderText">
+      <string>Texte</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="3">
+    <widget class="QPushButton" name="m_font_pb">
+     <property name="text">
+      <string>Police</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/