ORE Studio 0.0.4
Loading...
Searching...
No Matches
FlagIconHelper.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_FLAG_ICON_HELPER_HPP
21#define ORES_QT_FLAG_ICON_HELPER_HPP
22
23#include <QAction>
24#include <QComboBox>
25#include <QLineEdit>
26#include <QObject>
27#include "ores.qt/export.hpp"
28
29namespace ores::qt {
30
31class ImageCache;
32
36enum class FlagSource { Currency, Country, BusinessCentre };
37
51ORES_QT_API void apply_flag_icons(QComboBox* combo, ImageCache* cache, FlagSource source);
52
65ORES_QT_API void setup_flag_combo(
66 QObject* context, QComboBox* combo, ImageCache* cache, FlagSource source);
67
79template<typename Resolver>
80void set_combo_flag_icons(QComboBox* combo, Resolver&& resolver) {
81 for (int i = 0; i < combo->count(); ++i) {
82 const std::string code = combo->itemText(i).toStdString();
83 combo->setItemIcon(i, resolver(code));
84 }
85 combo->update();
86}
87
101 QLineEdit* edit, const QIcon& icon, QAction*& action_ptr) {
102 if (action_ptr) {
103 edit->removeAction(action_ptr);
104 delete action_ptr;
105 action_ptr = nullptr;
106 }
107 if (!icon.isNull()) {
108 action_ptr = edit->addAction(icon, QLineEdit::LeadingPosition);
109 }
110}
111
112}
113
114#endif
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
ORES_QT_API void apply_flag_icons(QComboBox *combo, ImageCache *cache, FlagSource source)
Apply flag icons to a combo box using the given image cache.
Definition FlagIconHelper.cpp:25
FlagSource
The type of flag icons to apply to a combo box.
Definition FlagIconHelper.hpp:36
ORES_QT_API void setup_flag_combo(QObject *context, QComboBox *combo, ImageCache *cache, FlagSource source)
Wire up a combo box for flag icons and keep them current.
Definition FlagIconHelper.cpp:43
void set_combo_flag_icons(QComboBox *combo, Resolver &&resolver)
Set flag icons on every item in a QComboBox.
Definition FlagIconHelper.hpp:80
void set_line_edit_flag_icon(QLineEdit *edit, const QIcon &icon, QAction *&action_ptr)
Set a leading flag icon on a standalone QLineEdit.
Definition FlagIconHelper.hpp:100