do not use hardcoded image formats, load dynamically - fixes #834 for Qt-6 based builds
This commit is contained in:
		
							parent
							
								
									de09d34618
								
							
						
					
					
						commit
						548f10aab1
					
				
					 3 changed files with 51 additions and 30 deletions
				
			
		|  | @ -49,7 +49,7 @@ pip3 install -U pip | ||||||
| pip3 install -I aqtinstall | pip3 install -I aqtinstall | ||||||
| 
 | 
 | ||||||
| if ($qt_version.StartsWith("6")) { | if ($qt_version.StartsWith("6")) { | ||||||
|   aqt install-qt -O "$qt_path" windows desktop $qt_version win64_msvc2019_64 -m qtwebengine qtmultimedia qt5compat qtwebchannel qtpositioning |   aqt install-qt -O "$qt_path" windows desktop $qt_version win64_msvc2019_64 -m qtwebengine qtimageformats qtmultimedia qt5compat qtwebchannel qtpositioning | ||||||
| } | } | ||||||
| else { | else { | ||||||
|   aqt install-qt -O "$qt_path" windows desktop $qt_version win64_msvc2019_64 -m qtwebengine |   aqt install-qt -O "$qt_path" windows desktop $qt_version win64_msvc2019_64 -m qtwebengine | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "services/abstract/gui/formcategorydetails.h" | #include "services/abstract/gui/formcategorydetails.h" | ||||||
| 
 | 
 | ||||||
|  | #include "3rd-party/boolinq/boolinq.h" | ||||||
| #include "core/feedsmodel.h" | #include "core/feedsmodel.h" | ||||||
| #include "database/databasequeries.h" | #include "database/databasequeries.h" | ||||||
| #include "definitions/definitions.h" | #include "definitions/definitions.h" | ||||||
|  | @ -18,6 +19,7 @@ | ||||||
| #include <QAction> | #include <QAction> | ||||||
| #include <QDialogButtonBox> | #include <QDialogButtonBox> | ||||||
| #include <QFileDialog> | #include <QFileDialog> | ||||||
|  | #include <QImageReader> | ||||||
| #include <QLineEdit> | #include <QLineEdit> | ||||||
| #include <QMenu> | #include <QMenu> | ||||||
| #include <QPushButton> | #include <QPushButton> | ||||||
|  | @ -41,10 +43,11 @@ FormCategoryDetails::~FormCategoryDetails() { | ||||||
| void FormCategoryDetails::createConnections() { | void FormCategoryDetails::createConnections() { | ||||||
|   // General connections.
 |   // General connections.
 | ||||||
|   connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormCategoryDetails::apply); |   connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormCategoryDetails::apply); | ||||||
|   connect(m_ui->m_txtTitle->lineEdit(), &BaseLineEdit::textChanged, |   connect(m_ui->m_txtTitle->lineEdit(), &BaseLineEdit::textChanged, this, &FormCategoryDetails::onTitleChanged); | ||||||
|           this, &FormCategoryDetails::onTitleChanged); |   connect(m_ui->m_txtDescription->lineEdit(), | ||||||
|   connect(m_ui->m_txtDescription->lineEdit(), &BaseLineEdit::textChanged, |           &BaseLineEdit::textChanged, | ||||||
|           this, &FormCategoryDetails::onDescriptionChanged); |           this, | ||||||
|  |           &FormCategoryDetails::onDescriptionChanged); | ||||||
| 
 | 
 | ||||||
|   // Icon connections.
 |   // Icon connections.
 | ||||||
|   connect(m_actionLoadIconFromFile, &QAction::triggered, this, &FormCategoryDetails::onLoadIconFromFile); |   connect(m_actionLoadIconFromFile, &QAction::triggered, this, &FormCategoryDetails::onLoadIconFromFile); | ||||||
|  | @ -55,9 +58,7 @@ void FormCategoryDetails::loadCategoryData() { | ||||||
|   loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot, m_category); |   loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot, m_category); | ||||||
| 
 | 
 | ||||||
|   if (m_creatingNew) { |   if (m_creatingNew) { | ||||||
|     GuiUtilities::applyDialogProperties(*this, |     GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("folder")), tr("Add new category")); | ||||||
|                                         qApp->icons()->fromTheme(QSL("folder")), |  | ||||||
|                                         tr("Add new category")); |  | ||||||
| 
 | 
 | ||||||
|     // Make sure that "default" icon is used as the default option for new
 |     // Make sure that "default" icon is used as the default option for new
 | ||||||
|     // categories.
 |     // categories.
 | ||||||
|  | @ -66,7 +67,8 @@ void FormCategoryDetails::loadCategoryData() { | ||||||
|     // Load parent from suggested item.
 |     // Load parent from suggested item.
 | ||||||
|     if (m_parentToSelect != nullptr) { |     if (m_parentToSelect != nullptr) { | ||||||
|       if (m_parentToSelect->kind() == RootItem::Kind::Category) { |       if (m_parentToSelect->kind() == RootItem::Kind::Category) { | ||||||
|         m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) m_parentToSelect))); |         m_ui->m_cmbParentCategory | ||||||
|  |           ->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)m_parentToSelect))); | ||||||
|       } |       } | ||||||
|       else if (m_parentToSelect->kind() == RootItem::Kind::Feed) { |       else if (m_parentToSelect->kind() == RootItem::Kind::Feed) { | ||||||
|         int target_item = m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)m_parentToSelect->parent())); |         int target_item = m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)m_parentToSelect->parent())); | ||||||
|  | @ -78,11 +80,10 @@ void FormCategoryDetails::loadCategoryData() { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     GuiUtilities::applyDialogProperties(*this, |     GuiUtilities::applyDialogProperties(*this, m_category->fullIcon(), tr("Edit \"%1\"").arg(m_category->title())); | ||||||
|                                         m_category->fullIcon(), |  | ||||||
|                                         tr("Edit \"%1\"").arg(m_category->title())); |  | ||||||
| 
 | 
 | ||||||
|     m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) m_category->parent()))); |     m_ui->m_cmbParentCategory | ||||||
|  |       ->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*)m_category->parent()))); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   m_ui->m_txtTitle->lineEdit()->setText(m_category->title()); |   m_ui->m_txtTitle->lineEdit()->setText(m_category->title()); | ||||||
|  | @ -93,7 +94,9 @@ void FormCategoryDetails::loadCategoryData() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FormCategoryDetails::apply() { | void FormCategoryDetails::apply() { | ||||||
|   RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>()); |   RootItem* parent = | ||||||
|  |     static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()) | ||||||
|  |                              .value<void*>()); | ||||||
| 
 | 
 | ||||||
|   m_category->setTitle(m_ui->m_txtTitle->lineEdit()->text()); |   m_category->setTitle(m_ui->m_txtTitle->lineEdit()->text()); | ||||||
|   m_category->setDescription(m_ui->m_txtDescription->lineEdit()->text()); |   m_category->setDescription(m_ui->m_txtDescription->lineEdit()->text()); | ||||||
|  | @ -139,8 +142,19 @@ void FormCategoryDetails::onDescriptionChanged(const QString& new_description) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FormCategoryDetails::onLoadIconFromFile() { | void FormCategoryDetails::onLoadIconFromFile() { | ||||||
|   QFileDialog dialog(this, tr("Select icon file for the category"), |   auto supported_formats = QImageReader::supportedImageFormats(); | ||||||
|                      qApp->homeFolder(), tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)")); |   auto prefixed_formats = boolinq::from(supported_formats) | ||||||
|  |                             .select([](const QByteArray& frmt) { | ||||||
|  |                               return QSL("*.%1").arg(frmt); | ||||||
|  |                             }) | ||||||
|  |                             .toStdList(); | ||||||
|  | 
 | ||||||
|  |   QStringList list_formats = FROM_STD_LIST(QStringList, prefixed_formats); | ||||||
|  | 
 | ||||||
|  |   QFileDialog dialog(this, | ||||||
|  |                      tr("Select icon file for the category"), | ||||||
|  |                      qApp->homeFolder(), | ||||||
|  |                      tr("Images (%1)").arg(list_formats.join(QL1C(' ')))); | ||||||
| 
 | 
 | ||||||
|   dialog.setFileMode(QFileDialog::FileMode::ExistingFile); |   dialog.setFileMode(QFileDialog::FileMode::ExistingFile); | ||||||
|   dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic"))); |   dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic"))); | ||||||
|  | @ -178,12 +192,10 @@ void FormCategoryDetails::initialize() { | ||||||
| 
 | 
 | ||||||
|   // Setup menu & actions for icon selection.
 |   // Setup menu & actions for icon selection.
 | ||||||
|   m_iconMenu = new QMenu(tr("Icon selection"), this); |   m_iconMenu = new QMenu(tr("Icon selection"), this); | ||||||
|   m_actionLoadIconFromFile = new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")), |   m_actionLoadIconFromFile = | ||||||
|                                          tr("Load icon from file..."), |     new QAction(qApp->icons()->fromTheme(QSL("image-x-generic")), tr("Load icon from file..."), this); | ||||||
|                                          this); |   m_actionUseDefaultIcon = | ||||||
|   m_actionUseDefaultIcon = new QAction(qApp->icons()->fromTheme(QSL("folder")), |     new QAction(qApp->icons()->fromTheme(QSL("folder")), tr("Use default icon from icon theme"), this); | ||||||
|                                        tr("Use default icon from icon theme"), |  | ||||||
|                                        this); |  | ||||||
|   m_iconMenu->addAction(m_actionLoadIconFromFile); |   m_iconMenu->addAction(m_actionLoadIconFromFile); | ||||||
|   m_iconMenu->addAction(m_actionUseDefaultIcon); |   m_iconMenu->addAction(m_actionUseDefaultIcon); | ||||||
|   m_ui->m_btnIcon->setMenu(m_iconMenu); |   m_ui->m_btnIcon->setMenu(m_iconMenu); | ||||||
|  | @ -199,9 +211,7 @@ void FormCategoryDetails::initialize() { | ||||||
| void FormCategoryDetails::loadCategories(const QList<Category*>& categories, | void FormCategoryDetails::loadCategories(const QList<Category*>& categories, | ||||||
|                                          RootItem* root_item, |                                          RootItem* root_item, | ||||||
|                                          Category* input_category) { |                                          Category* input_category) { | ||||||
|   m_ui->m_cmbParentCategory->addItem(root_item->icon(), |   m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*)root_item)); | ||||||
|                                      root_item->title(), |  | ||||||
|                                      QVariant::fromValue((void*) root_item)); |  | ||||||
| 
 | 
 | ||||||
|   for (Category* category : categories) { |   for (Category* category : categories) { | ||||||
|     if (input_category != nullptr && (category == input_category || category->isChildOf(input_category))) { |     if (input_category != nullptr && (category == input_category || category->isChildOf(input_category))) { | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "services/standard/gui/standardfeeddetails.h" | #include "services/standard/gui/standardfeeddetails.h" | ||||||
| 
 | 
 | ||||||
|  | #include "3rd-party/boolinq/boolinq.h" | ||||||
| #include "exceptions/applicationexception.h" | #include "exceptions/applicationexception.h" | ||||||
| #include "exceptions/networkexception.h" | #include "exceptions/networkexception.h" | ||||||
| #include "exceptions/scriptexception.h" | #include "exceptions/scriptexception.h" | ||||||
|  | @ -13,6 +14,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <QClipboard> | #include <QClipboard> | ||||||
| #include <QFileDialog> | #include <QFileDialog> | ||||||
|  | #include <QImageReader> | ||||||
| #include <QMenu> | #include <QMenu> | ||||||
| #include <QMimeData> | #include <QMimeData> | ||||||
| #include <QTextCodec> | #include <QTextCodec> | ||||||
|  | @ -276,10 +278,19 @@ void StandardFeedDetails::onPostProcessScriptChanged(const QString& new_pp) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void StandardFeedDetails::onLoadIconFromFile() { | void StandardFeedDetails::onLoadIconFromFile() { | ||||||
|  |   auto supported_formats = QImageReader::supportedImageFormats(); | ||||||
|  |   auto prefixed_formats = boolinq::from(supported_formats) | ||||||
|  |                             .select([](const QByteArray& frmt) { | ||||||
|  |                               return QSL("*.%1").arg(frmt); | ||||||
|  |                             }) | ||||||
|  |                             .toStdList(); | ||||||
|  | 
 | ||||||
|  |   QStringList list_formats = FROM_STD_LIST(QStringList, prefixed_formats); | ||||||
|  | 
 | ||||||
|   QFileDialog dialog(this, |   QFileDialog dialog(this, | ||||||
|                      tr("Select icon file for the feed"), |                      tr("Select icon file for the feed"), | ||||||
|                      qApp->homeFolder(), |                      qApp->homeFolder(), | ||||||
|                      tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)")); |                      tr("Images (%1)").arg(list_formats.join(QL1C(' ')))); | ||||||
| 
 | 
 | ||||||
|   dialog.setFileMode(QFileDialog::FileMode::ExistingFile); |   dialog.setFileMode(QFileDialog::FileMode::ExistingFile); | ||||||
|   dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic"))); |   dialog.setWindowIcon(qApp->icons()->fromTheme(QSL("image-x-generic"))); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue