Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Show actual fonts in font dropdowns (#2080)

manongjohnb66bc4e31367
diff --git a/toonz/sources/common/tvrender/tfont_qt.cpp b/toonz/sources/common/tvrender/tfont_qt.cpp
index 1080fd17d..96d558883 100644
--- a/toonz/sources/common/tvrender/tfont_qt.cpp
+++ b/toonz/sources/common/tvrender/tfont_qt.cpp
@@ -429,7 +429,8 @@ void TFontManager::getAllFamilies(vector<wstring> &families) const {
QStringList::const_iterator it = qFamilies.begin();
for (; it != qFamilies.end(); ++it) {
- families.push_back(it->toStdWString());
+ if (!m_pimpl->m_qfontdb->isPrivateFamily(*it))
+ families.push_back(it->toStdWString());
}
}
diff --git a/toonz/sources/include/tools/toolhandle.h b/toonz/sources/include/tools/toolhandle.h
index e11af611c..e68dbb12b 100644
--- a/toonz/sources/include/tools/toolhandle.h
+++ b/toonz/sources/include/tools/toolhandle.h
@@ -65,7 +65,13 @@ public:
void notifyToolChanged() { emit toolChanged(); }
void notifyToolCursorTypeChanged() { emit toolCursorTypeChanged(); }
+
+ void notifyToolComboBoxListChanged(std::string id) {
+ emit toolComboBoxListChanged(id);
+ }
+
signals:
+ void toolComboBoxListChanged(std::string);
void toolSwitched();
void toolChanged();
void toolEditingFinished();
diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.h
index fe87b195e..2d5db494d 100644
--- a/toonz/sources/include/tools/tooloptions.h
+++ b/toonz/sources/include/tools/tooloptions.h
@@ -146,7 +146,7 @@ public:
enum SingleValueWidgetType { SLIDER = 0, FIELD };
void setSingleValueWidgetType(int type) { m_singleValueWidgetType = type; }
- enum EnumWidgetType { COMBOBOX = 0, POPUPBUTTON };
+ enum EnumWidgetType { COMBOBOX = 0, POPUPBUTTON, FONTCOMBOBOX };
void setEnumWidgetType(int type) { m_enumWidgetType = type; }
private:
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h
index 5d8aacc3d..9ea120247 100644
--- a/toonz/sources/include/toonz/preferences.h
+++ b/toonz/sources/include/toonz/preferences.h
@@ -238,6 +238,8 @@ public:
void setInterfaceFont(std::string font);
QString getInterfaceFont() { return m_interfaceFont; }
+ void setInterfaceFontStyle(std::string style);
+ QString getInterfaceFontStyle() { return m_interfaceFontStyle; }
void setInterfaceFontWeight(int weight);
int getInterfaceFontWeight() { return m_interfaceFontWeight; }
@@ -589,7 +591,7 @@ private:
QString m_units, m_cameraUnits, m_scanLevelType, m_currentRoomChoice,
m_oldUnits, m_oldCameraUnits, m_ffmpegPath, m_shortcutPreset,
- m_customProjectRoot, m_interfaceFont;
+ m_customProjectRoot, m_interfaceFont, m_interfaceFontStyle;
QString m_fastRenderPath;
double m_defLevelWidth, m_defLevelHeight, m_defLevelDpi;
diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cpp
index 1cc30f61f..7db4e2af3 100644
--- a/toonz/sources/tnztools/tooloptions.cpp
+++ b/toonz/sources/tnztools/tooloptions.cpp
@@ -365,6 +365,17 @@ void ToolOptionControlBuilder::visit(TEnumProperty *p) {
break;
}
+ case FONTCOMBOBOX: {
+ if (p->getQStringName() != "") {
+ QLabel *label = addLabel(p);
+ m_panel->addLabel(p->getName(), label);
+ }
+ ToolOptionFontCombo *obj = new ToolOptionFontCombo(m_tool, p, m_toolHandle);
+ control = obj;
+ widget = obj;
+ break;
+ }
+
case COMBOBOX:
default: {
if (p->getQStringName() != "") {
@@ -1526,22 +1537,28 @@ TypeToolOptionsBox::TypeToolOptionsBox(QWidget *parent, TTool *tool,
assert(props->getPropertyCount() > 0);
ToolOptionControlBuilder builder(this, tool, pltHandle, toolHandle);
+ builder.setEnumWidgetType(ToolOptionControlBuilder::FONTCOMBOBOX);
if (tool && tool->getProperties(0)) tool->getProperties(0)->accept(builder);
+ builder.setEnumWidgetType(ToolOptionControlBuilder::COMBOBOX);
+ if (tool && tool->getProperties(1)) tool->getProperties(1)->accept(builder);
m_layout->addStretch(0);
bool ret = true;
- ToolOptionCombo *fontField =
- dynamic_cast<ToolOptionCombo *>(m_controls.value("Font:"));
+
+ ToolOptionFontCombo *fontField =
+ dynamic_cast<ToolOptionFontCombo *>(m_controls.value("Font:"));
ret &&connect(fontField, SIGNAL(currentIndexChanged(int)), this,
SLOT(onFieldChanged()));
-#ifndef MACOSX
+ //#ifndef MACOSX
ToolOptionCombo *styleField =
dynamic_cast<ToolOptionCombo *>(m_controls.value("Style:"));
ret &&connect(styleField, SIGNAL(currentIndexChanged(int)), this,
SLOT(onFieldChanged()));
-#endif
+ ret &&connect(toolHandle, SIGNAL(toolComboBoxListChanged(std::string)),
+ styleField, SLOT(reloadComboBoxList(std::string)));
+ //#endif
ToolOptionCombo *sizeField =
dynamic_cast<ToolOptionCombo *>(m_controls.value("Size:"));
diff --git a/toonz/sources/tnztools/tooloptionscontrols.cpp b/toonz/sources/tnztools/tooloptionscontrols.cpp
index f257158ab..b34af7d83 100644
--- a/toonz/sources/tnztools/tooloptionscontrols.cpp
+++ b/toonz/sources/tnztools/tooloptionscontrols.cpp
@@ -571,8 +571,16 @@ ToolOptionCombo::ToolOptionCombo(TTool *tool, TEnumProperty *property,
setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int)));
// synchronize the state with the same widgets in other tool option bars
- if (toolHandle)
+ if (toolHandle) {
connect(this, SIGNAL(activated(int)), toolHandle, SIGNAL(toolChanged()));
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void ToolOptionCombo::reloadComboBoxList(std::string id) {
+ if (id == "" || m_property->getName() != id) return;
+ loadEntries();
}
//-----------------------------------------------------------------------------
@@ -682,6 +690,58 @@ void ToolOptionCombo::doOnActivated(int index) {
//=============================================================================
+ToolOptionFontCombo::ToolOptionFontCombo(TTool *tool, TEnumProperty *property,
+ ToolHandle *toolHandle)
+ : QFontComboBox()
+ , ToolOptionControl(tool, property->getName(), toolHandle)
+ , m_property(property) {
+ setMaximumWidth(250);
+ m_property->addListener(this);
+ setSizeAdjustPolicy(QFontComboBox::AdjustToContents);
+ connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int)));
+ // synchronize the state with the same widgets in other tool option bars
+ if (toolHandle)
+ connect(this, SIGNAL(activated(int)), toolHandle, SIGNAL(toolChanged()));
+
+ updateStatus();
+}
+
+//-----------------------------------------------------------------------------
+
+void ToolOptionFontCombo::updateStatus() {
+ QString value = QString::fromStdWString(m_property->getValue());
+ int index = findText(value);
+ if (index >= 0 && index != currentIndex()) setCurrentIndex(index);
+}
+
+//-----------------------------------------------------------------------------
+
+void ToolOptionFontCombo::onActivated(int index) {
+ const TEnumProperty::Range &range = m_property->getRange();
+ if (index < 0 || index >= (int)range.size()) return;
+
+ std::wstring item = range[index];
+ m_property->setValue(item);
+ notifyTool();
+}
+
+//-----------------------------------------------------------------------------
+
+void ToolOptionFontCombo::doShowPopup() {
+ if (!isInVisibleViewer(this)) return;
+ if (Preferences::instance()->getDropdownShortcutsCycleOptions()) {
+ const TEnumProperty::Range &range = m_property->getRange();
+ int theIndex = currentIndex() + 1;
+ if (theIndex >= (int)range.size()) theIndex = 0;
+ onActivated(theIndex);
+ setCurrentIndex(theIndex);
+ } else {
+ if (isVisible()) showPopup();
+ }
+}
+
+//=============================================================================
+
ToolOptionPopupButton::ToolOptionPopupButton(TTool *tool,
TEnumProperty *property)
: PopupButton()
diff --git a/toonz/sources/tnztools/tooloptionscontrols.h b/toonz/sources/tnztools/tooloptionscontrols.h
index 4e6480852..6e733c6b9 100644
--- a/toonz/sources/tnztools/tooloptionscontrols.h
+++ b/toonz/sources/tnztools/tooloptionscontrols.h
@@ -29,6 +29,7 @@
// Qt includes
#include <QComboBox>
+#include <QFontComboBox>
#include <QToolButton>
#include <QTimer>
#include <QLabel>
@@ -202,7 +203,30 @@ protected:
public:
ToolOptionCombo(TTool *tool, TEnumProperty *property,
ToolHandle *toolHandle = 0);
+ void updateStatus() override;
+
+ TEnumProperty *getProperty() const { return m_property; }
+
+public slots:
+ void reloadComboBoxList(std::string);
void loadEntries();
+ void onActivated(int);
+ void doShowPopup();
+ void doOnActivated(int);
+};
+
+//-----------------------------------------------------------------------------
+
+class ToolOptionFontCombo final : public QFontComboBox,
+ public ToolOptionControl {
+ Q_OBJECT
+
+protected:
+ TEnumProperty *m_property;
+
+public:
+ ToolOptionFontCombo(TTool *tool, TEnumProperty *property,
+ ToolHandle *toolHandle = 0);
void updateStatus() override;
TEnumProperty *getProperty() const { return m_property; }
@@ -211,7 +235,6 @@ public slots:
void onActivated(int);
void doShowPopup();
- void doOnActivated(int);
};
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/tnztools/typetool.cpp b/toonz/sources/tnztools/typetool.cpp
index 3739c523a..67add75d7 100644
--- a/toonz/sources/tnztools/typetool.cpp
+++ b/toonz/sources/tnztools/typetool.cpp
@@ -295,7 +295,7 @@ class TypeTool final : public TTool {
TEnumProperty m_typeFaceMenu;
TBoolProperty m_vertical;
TEnumProperty m_size;
- TPropertyGroup m_prop;
+ TPropertyGroup m_prop[2];
// valori correnti di alcune Properties,
// duplicati per permettere controlli sulla validita' o per ottimizzazione
@@ -389,7 +389,9 @@ public:
bool onPropertyChanged(std::string propertyName) override;
- TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
+ TPropertyGroup *getProperties(int targetType) override {
+ return &m_prop[targetType];
+ }
int getColorClass() const { return 1; }
@@ -421,15 +423,15 @@ TypeTool::TypeTool()
, m_size("Size:") // W_ToolOptions_Size
, m_undo(0) {
bind(TTool::CommonLevels | TTool::EmptyTarget);
- m_prop.bind(m_fontFamilyMenu);
+ m_prop[0].bind(m_fontFamilyMenu);
// Su mac non e' visibile il menu dello style perche' e' stato inserito nel
// nome
// della font.
//#ifndef MACOSX
- m_prop.bind(m_typeFaceMenu);
+ m_prop[1].bind(m_typeFaceMenu);
//#endif
- m_prop.bind(m_size);
- m_prop.bind(m_vertical);
+ m_prop[1].bind(m_size);
+ m_prop[1].bind(m_vertical);
m_vertical.setId("Orientation");
m_fontFamilyMenu.setId("TypeFont");
m_typeFaceMenu.setId("TypeStyle");
@@ -537,6 +539,9 @@ void TypeTool::initTypeFaces() {
it != typefaces.end(); ++it)
m_typeFaceMenu.addValue(*it);
if (m_typeFaceMenu.isValue(oldTypeface)) m_typeFaceMenu.setValue(oldTypeface);
+
+ TTool::getApplication()->getCurrentTool()->notifyToolComboBoxListChanged(
+ m_typeFaceMenu.getName());
}
//---------------------------------------------------------
diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cpp
index 4ddea246e..676c7ca3a 100644
--- a/toonz/sources/toonz/main.cpp
+++ b/toonz/sources/toonz/main.cpp
@@ -62,6 +62,7 @@
#include "tsimplecolorstyles.h"
#include "toonz/imagestyles.h"
#include "tvectorbrushstyle.h"
+#include "tfont.h"
#ifdef MACOSX
#include "tipc.h"
@@ -682,16 +683,26 @@ int main(int argc, char *argv[]) {
}
QFont *myFont;
- std::string fontName =
- Preferences::instance()->getInterfaceFont().toStdString();
- std::string isBold =
- Preferences::instance()->getInterfaceFontWeight() ? "Yes" : "No";
- myFont = new QFont(QString::fromStdString(fontName));
+ QString fontName = Preferences::instance()->getInterfaceFont();
+ QString fontStyle = Preferences::instance()->getInterfaceFontStyle();
+
+ TFontManager *fontMgr = TFontManager::instance();
+ std::vector<std::wstring> typefaces;
+ fontMgr->loadFontNames();
+ fontMgr->setFamily(fontName.toStdWString());
+ fontMgr->getAllTypefaces(typefaces);
+
+ bool isBold = false, isItalic = false, hasKerning = false;
+ isBold = fontMgr->isBold(fontName, fontStyle);
+ isItalic = fontMgr->isItalic(fontName, fontStyle);
+ hasKerning = fontMgr->hasKerning();
+
+ myFont = new QFont(fontName);
myFont->setPixelSize(EnvSoftwareCurrentFontSize);
- if (strcmp(isBold.c_str(), "Yes") == 0)
- myFont->setBold(true);
- else
- myFont->setBold(false);
+ myFont->setBold(isBold);
+ myFont->setItalic(isItalic);
+ myFont->setKerning(hasKerning);
+
a.setFont(*myFont);
QAction *action = CommandManager::instance()->getAction("MI_OpenTMessage");
diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp
index 5808025b2..50a6fe3ea 100644
--- a/toonz/sources/toonz/preferencespopup.cpp
+++ b/toonz/sources/toonz/preferencespopup.cpp
@@ -38,6 +38,7 @@
// Qt includes
#include <QHBoxLayout>
#include <QComboBox>
+#include <QFontComboBox>
#include <QLabel>
#include <QStackedWidget>
#include <QLineEdit>
@@ -353,10 +354,31 @@ void PreferencesPopup::onDropdownShortcutsCycleOptionsChanged(int index) {
}
//-----------------------------------------------------------------------------
+void PreferencesPopup::rebuilldFontStyleList() {
+ TFontManager *instance = TFontManager::instance();
+ std::vector<std::wstring> typefaces;
+ QString font = m_interfaceFont->currentText();
+ instance->loadFontNames();
+ instance->setFamily(font.toStdWString());
+ instance->getAllTypefaces(typefaces);
+ m_interfaceFontStyle->clear();
+ for (std::vector<std::wstring>::iterator it = typefaces.begin();
+ it != typefaces.end(); ++it)
+ m_interfaceFontStyle->addItem(QString::fromStdWString(*it));
+}
void PreferencesPopup::onInterfaceFontChanged(int index) {
QString font = m_interfaceFont->currentText();
m_pref->setInterfaceFont(font.toStdString());
+
+ QString oldTypeface = m_interfaceFontStyle->currentText();
+ rebuilldFontStyleList();
+ if (!oldTypeface.isEmpty()) {
+ int newIndex = m_interfaceFontStyle->findText(oldTypeface);
+ if (newIndex < 0) newIndex = 0;
+ m_interfaceFontStyle->setCurrentIndex(newIndex);
+ }
+
if (font.contains("Comic Sans"))
DVGui::warning(tr("Life is too short for Comic Sans"));
if (font.contains("Wingdings"))
@@ -365,8 +387,9 @@ void PreferencesPopup::onInterfaceFontChanged(int index) {
//-----------------------------------------------------------------------------
-void PreferencesPopup::onInterfaceFontWeightChanged(int index) {
- m_pref->setInterfaceFontWeight(index);
+void PreferencesPopup::onInterfaceFontStyleChanged(int index) {
+ QString style = m_interfaceFontStyle->itemText(index);
+ m_pref->setInterfaceFontStyle(style.toStdString());
}
//-----------------------------------------------------------------------------
@@ -1313,8 +1336,8 @@ PreferencesPopup::PreferencesPopup()
new QLabel(tr("* Changes will take effect the next time you run Toonz"));
note_interface->setStyleSheet("font-size: 10px; font: italic;");
- m_interfaceFont = new QComboBox(this);
- m_interfaceFontWeight = new QComboBox(this);
+ m_interfaceFont = new QFontComboBox(this);
+ m_interfaceFontStyle = new QComboBox(this);
m_colorCalibration =
new QGroupBox(tr("Color Calibration using 3D Look-up Table *"));
@@ -1661,32 +1684,10 @@ PreferencesPopup::PreferencesPopup()
viewerZoomCenterComboBox->addItems(zoomCenters);
viewerZoomCenterComboBox->setCurrentIndex(m_pref->getViewerZoomCenter());
- TFontManager *instance = TFontManager::instance();
- bool validFonts;
- try {
- instance->loadFontNames();
- validFonts = true;
- } catch (TFontLibraryLoadingError &) {
- validFonts = false;
- // TMessage::error(toString(e.getMessage()));
- }
-
- if (validFonts) {
- std::vector<std::wstring> names;
- instance->getAllFamilies(names);
-
- for (std::vector<std::wstring>::iterator it = names.begin();
- it != names.end(); ++it)
- m_interfaceFont->addItem(QString::fromStdWString(*it));
-
- m_interfaceFont->setCurrentText(m_pref->getInterfaceFont());
- }
+ m_interfaceFont->setCurrentText(m_pref->getInterfaceFont());
- QStringList fontStyles;
- fontStyles << "Regular"
- << "Bold";
- m_interfaceFontWeight->addItems(fontStyles);
- m_interfaceFontWeight->setCurrentIndex(m_pref->getInterfaceFontWeight());
+ rebuilldFontStyleList();
+ m_interfaceFontStyle->setCurrentText(m_pref->getInterfaceFontStyle());
m_colorCalibration->setCheckable(true);
m_colorCalibration->setChecked(m_pref->isColorCalibrationEnabled());
@@ -2092,8 +2093,8 @@ PreferencesPopup::PreferencesPopup()
{
fontLay->addWidget(m_interfaceFont);
fontLay->addSpacing(10);
- fontLay->addWidget(new QLabel(tr("Weight *:")));
- fontLay->addWidget(m_interfaceFontWeight);
+ fontLay->addWidget(new QLabel(tr("Style *:")));
+ fontLay->addWidget(m_interfaceFontStyle);
fontLay->addStretch(1);
}
interfaceBottomLay->addLayout(fontLay, 4, 1, 1, 5);
@@ -2714,8 +2715,8 @@ PreferencesPopup::PreferencesPopup()
this, SLOT(onViewerZoomCenterChanged(int)));
ret = ret && connect(m_interfaceFont, SIGNAL(currentIndexChanged(int)), this,
SLOT(onInterfaceFontChanged(int)));
- ret = ret && connect(m_interfaceFontWeight, SIGNAL(currentIndexChanged(int)),
- this, SLOT(onInterfaceFontWeightChanged(int)));
+ ret = ret && connect(m_interfaceFontStyle, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(onInterfaceFontStyleChanged(int)));
ret = ret && connect(replaceAfterSaveLevelAsCB, SIGNAL(stateChanged(int)),
this, SLOT(onReplaceAfterSaveLevelAsChanged(int)));
ret =
diff --git a/toonz/sources/toonz/preferencespopup.h b/toonz/sources/toonz/preferencespopup.h
index 474e2306f..057183e45 100644
--- a/toonz/sources/toonz/preferencespopup.h
+++ b/toonz/sources/toonz/preferencespopup.h
@@ -16,6 +16,7 @@
// Qt includes
#include <QComboBox>
+#include <QFontComboBox>
//==============================================================
@@ -55,9 +56,10 @@ private:
*m_defLevelType, *m_autocreationType, *m_levelFormatNames,
*m_columnIconOm, *m_unitOm, *m_cameraUnitOm, *m_importPolicy,
*m_vectorSnappingTargetCB, *m_dropdownShortcutsCycleOptionsCB,
- *m_interfaceFont, *m_interfaceFontWeight, *m_guidedDrawingStyle,
- *m_functionEditorToggle, *m_cursorBrushType, *m_cursorBrushStyle,
- *m_xsheetLayout;
+ *m_guidedDrawingStyle, *m_functionEditorToggle, *m_cursorBrushType,
+ *m_cursorBrushStyle, *m_xsheetLayout, *m_interfaceFontStyle;
+
+ QFontComboBox *m_interfaceFont;
DVGui::MeasuredDoubleLineEdit *m_defLevelWidth, *m_defLevelHeight;
@@ -94,6 +96,7 @@ private:
private:
// QWidget* create(const QString& lbl, bool def, const char* slot);
void rebuildFormatsList();
+ void rebuilldFontStyleList();
private slots:
@@ -202,7 +205,7 @@ private slots:
void onShortcutCommandsWhileRenamingCellClicked(int);
void onWatchFileSystemClicked(int);
void onInterfaceFontChanged(int index);
- void onInterfaceFontWeightChanged(int index);
+ void onInterfaceFontStyleChanged(int index);
void onXsheetLayoutChanged(int index);
void onPathAliasPriorityChanged(int index);
void onShowCurrentTimelineChanged(int);
diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp
index 85a0b1ac8..8f5975d46 100644
--- a/toonz/sources/toonzlib/preferences.cpp
+++ b/toonz/sources/toonzlib/preferences.cpp
@@ -231,6 +231,7 @@ Preferences::Preferences()
#else
, m_interfaceFont("Helvetica")
#endif
+ , m_interfaceFontStyle("Regular")
, m_interfaceFontWeight(0)
, m_defLevelWidth(0.0)
, m_defLevelHeight(0.0)
@@ -635,6 +636,10 @@ Preferences::Preferences()
QString interfaceFont = m_settings->value("interfaceFont").toString();
if (interfaceFont != "") m_interfaceFont = interfaceFont;
setInterfaceFont(m_interfaceFont.toStdString());
+ QString interfaceFontStyle =
+ m_settings->value("interfaceFontStyle").toString();
+ if (interfaceFontStyle != "") m_interfaceFontStyle = interfaceFontStyle;
+ setInterfaceFontStyle(m_interfaceFontStyle.toStdString());
getValue(*m_settings, "interfaceFontWeight", m_interfaceFontWeight);
getValue(*m_settings, "useNumpadForSwitchingStyles",
m_useNumpadForSwitchingStyles);
@@ -1319,6 +1324,13 @@ void Preferences::setInterfaceFont(std::string font) {
//-----------------------------------------------------------------
+void Preferences::setInterfaceFontStyle(std::string style) {
+ m_interfaceFontStyle = QString::fromStdString(style);
+ m_settings->setValue("interfaceFontStyle", m_interfaceFontStyle);
+}
+
+//-----------------------------------------------------------------
+
void Preferences::setInterfaceFontWeight(int weight) {
m_interfaceFontWeight = weight;
m_settings->setValue("interfaceFontWeight", m_interfaceFontWeight);