mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:00:04 +00:00
Add custom marker icons, and rework how marker icons are handled.
This commit is contained in:
parent
3685599693
commit
5bb4a7f95a
10 changed files with 368 additions and 204 deletions
|
|
@ -8,7 +8,6 @@
|
|||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
|
@ -16,6 +15,7 @@
|
|||
#include <QPixmap>
|
||||
#include <QColorDialog>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -36,6 +36,8 @@ public:
|
|||
}
|
||||
|
||||
void show_color_dialog();
|
||||
void show_icon_file_dialog();
|
||||
|
||||
void set_icon_color(const std::string& color);
|
||||
|
||||
void connect_signals();
|
||||
|
|
@ -45,24 +47,20 @@ public:
|
|||
|
||||
EditMarkerDialog* self_;
|
||||
QPushButton* deleteButton_;
|
||||
QIcon get_colored_icon(size_t index, const std::string& color);
|
||||
QIcon get_colored_icon(const types::MarkerIconInfo& marker,
|
||||
const std::string& color);
|
||||
|
||||
std::shared_ptr<manager::MarkerManager> markerManager_ =
|
||||
manager::MarkerManager::Instance();
|
||||
const std::vector<types::MarkerIconInfo>* icons_;
|
||||
types::MarkerId editId_;
|
||||
bool adding_;
|
||||
std::string setIconOnAdded_{""};
|
||||
};
|
||||
|
||||
QIcon EditMarkerDialog::Impl::get_colored_icon(size_t index,
|
||||
const std::string& color)
|
||||
QIcon EditMarkerDialog::Impl::get_colored_icon(
|
||||
const types::MarkerIconInfo& marker, const std::string& color)
|
||||
{
|
||||
if (index >= icons_->size())
|
||||
{
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
return util::modulateColors((*icons_)[index].qIcon,
|
||||
return util::modulateColors(marker.qIcon,
|
||||
self_->ui->iconComboBox->iconSize(),
|
||||
QColor(QString::fromStdString(color)));
|
||||
}
|
||||
|
|
@ -74,12 +72,11 @@ EditMarkerDialog::EditMarkerDialog(QWidget* parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
p->icons_ = &types::getMarkerIcons();
|
||||
for (auto& markerIcon : (*p->icons_))
|
||||
for (auto& markerIcon : p->markerManager_->get_icons())
|
||||
{
|
||||
ui->iconComboBox->addItem(markerIcon.qIcon,
|
||||
ui->iconComboBox->addItem(markerIcon.second.qIcon,
|
||||
QString(""),
|
||||
QString::fromStdString(markerIcon.name));
|
||||
QString::fromStdString(markerIcon.second.name));
|
||||
}
|
||||
p->deleteButton_ =
|
||||
ui->buttonBox->addButton("Delete", QDialogButtonBox::DestructiveRole);
|
||||
|
|
@ -98,7 +95,6 @@ void EditMarkerDialog::setup()
|
|||
|
||||
void EditMarkerDialog::setup(double latitude, double longitude)
|
||||
{
|
||||
ui->iconComboBox->setCurrentIndex(0);
|
||||
// By default use foreground color as marker color, mainly so the icons
|
||||
// are vissable in the dropdown menu.
|
||||
QColor color = QWidget::palette().color(QWidget::foregroundRole());
|
||||
|
|
@ -106,7 +102,7 @@ void EditMarkerDialog::setup(double latitude, double longitude)
|
|||
"",
|
||||
latitude,
|
||||
longitude,
|
||||
ui->iconComboBox->currentData().toString().toStdString(),
|
||||
manager::MarkerManager::getDefaultIconName(),
|
||||
boost::gil::rgba8_pixel_t {static_cast<uint8_t>(color.red()),
|
||||
static_cast<uint8_t>(color.green()),
|
||||
static_cast<uint8_t>(color.blue()),
|
||||
|
|
@ -128,6 +124,9 @@ void EditMarkerDialog::setup(types::MarkerId id)
|
|||
p->editId_ = id;
|
||||
p->adding_ = false;
|
||||
|
||||
std::string iconColorStr = util::color::ToArgbString(marker->iconColor);
|
||||
p->set_icon_color(iconColorStr);
|
||||
|
||||
int iconIndex =
|
||||
ui->iconComboBox->findData(QString::fromStdString(marker->iconName));
|
||||
if (iconIndex < 0 || marker->iconName == "")
|
||||
|
|
@ -135,15 +134,11 @@ void EditMarkerDialog::setup(types::MarkerId id)
|
|||
iconIndex = 0;
|
||||
}
|
||||
|
||||
std::string iconColorStr = util::color::ToArgbString(marker->iconColor);
|
||||
|
||||
ui->nameLineEdit->setText(QString::fromStdString(marker->name));
|
||||
ui->iconComboBox->setCurrentIndex(iconIndex);
|
||||
ui->latitudeDoubleSpinBox->setValue(marker->latitude);
|
||||
ui->longitudeDoubleSpinBox->setValue(marker->longitude);
|
||||
ui->iconColorLineEdit->setText(QString::fromStdString(iconColorStr));
|
||||
|
||||
p->set_icon_color(iconColorStr);
|
||||
}
|
||||
|
||||
types::MarkerInfo EditMarkerDialog::get_marker_info() const
|
||||
|
|
@ -163,7 +158,7 @@ types::MarkerInfo EditMarkerDialog::get_marker_info() const
|
|||
void EditMarkerDialog::Impl::show_color_dialog()
|
||||
{
|
||||
|
||||
QColorDialog* dialog = new QColorDialog(self_);
|
||||
auto* dialog = new QColorDialog(self_);
|
||||
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel);
|
||||
|
|
@ -187,6 +182,28 @@ void EditMarkerDialog::Impl::show_color_dialog()
|
|||
dialog->open();
|
||||
}
|
||||
|
||||
void EditMarkerDialog::Impl::show_icon_file_dialog()
|
||||
{
|
||||
|
||||
auto* dialog = new QFileDialog(self_);
|
||||
|
||||
dialog->setFileMode(QFileDialog::ExistingFile);
|
||||
dialog->setNameFilters({"Icon (*.png *.svg)", "All (*)"});
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
QObject::connect(dialog,
|
||||
&QFileDialog::fileSelected,
|
||||
self_,
|
||||
[this](const QString& file)
|
||||
{
|
||||
std::string path =
|
||||
QDir::toNativeSeparators(file).toStdString();
|
||||
setIconOnAdded_ = path;
|
||||
markerManager_->add_icon(path);
|
||||
});
|
||||
dialog->open();
|
||||
}
|
||||
|
||||
void EditMarkerDialog::Impl::connect_signals()
|
||||
{
|
||||
connect(self_,
|
||||
|
|
@ -217,7 +234,33 @@ void EditMarkerDialog::Impl::connect_signals()
|
|||
connect(self_->ui->iconColorButton,
|
||||
&QAbstractButton::clicked,
|
||||
self_,
|
||||
[=, this]() { self_->p->show_color_dialog(); });
|
||||
[=, this]() { show_color_dialog(); });
|
||||
|
||||
connect(self_->ui->iconFileOpenButton,
|
||||
&QPushButton::clicked,
|
||||
self_,
|
||||
[this]() { show_icon_file_dialog(); });
|
||||
|
||||
connect(markerManager_.get(),
|
||||
&manager::MarkerManager::IconAdded,
|
||||
self_,
|
||||
[this]()
|
||||
{
|
||||
std::string color =
|
||||
self_->ui->iconColorLineEdit->text().toStdString();
|
||||
set_icon_color(color);
|
||||
|
||||
if (setIconOnAdded_ != "")
|
||||
{
|
||||
int i = self_->ui->iconComboBox->findData(
|
||||
QString::fromStdString(setIconOnAdded_));
|
||||
if (i >= 0)
|
||||
{
|
||||
self_->ui->iconComboBox->setCurrentIndex(i);
|
||||
setIconOnAdded_ = "";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void EditMarkerDialog::Impl::set_icon_color(const std::string& color)
|
||||
|
|
@ -225,10 +268,25 @@ void EditMarkerDialog::Impl::set_icon_color(const std::string& color)
|
|||
self_->ui->iconColorFrame->setStyleSheet(
|
||||
QString::fromStdString(fmt::format("background-color: {}", color)));
|
||||
|
||||
for (size_t i = 0; i < icons_->size(); i++)
|
||||
auto* iconComboBox = self_->ui->iconComboBox;
|
||||
|
||||
|
||||
QVariant data = self_->ui->iconComboBox->currentData();
|
||||
self_->ui->iconComboBox->clear();
|
||||
for (auto& markerIcon : markerManager_->get_icons())
|
||||
{
|
||||
self_->ui->iconComboBox->setItemIcon(static_cast<int>(i),
|
||||
get_colored_icon(i, color));
|
||||
int i =
|
||||
iconComboBox->findData(QString::fromStdString(markerIcon.second.name));
|
||||
QIcon icon = get_colored_icon(markerIcon.second, color);
|
||||
if (i < 0)
|
||||
{
|
||||
iconComboBox->addItem(
|
||||
icon, QString(""), QString::fromStdString(markerIcon.second.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
self_->ui->iconComboBox->setItemIcon(i, icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class EditMarkerDialog : public QDialog
|
|||
|
||||
public:
|
||||
explicit EditMarkerDialog(QWidget* parent = nullptr);
|
||||
~EditMarkerDialog();
|
||||
~EditMarkerDialog() override;
|
||||
|
||||
void setup();
|
||||
void setup(double latitude, double longitude);
|
||||
|
|
|
|||
|
|
@ -7,88 +7,14 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>211</height>
|
||||
<height>249</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Edit Location Marker</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="iconComboBox">
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Latitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="longitudeDoubleSpinBox">
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-180.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>180.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="nameLineEdit"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="latitudeDoubleSpinBox">
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-90.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>90.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Longitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="9" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
|
|
@ -101,14 +27,7 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Icon Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="iconColorFrame">
|
||||
|
|
@ -146,6 +65,103 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QDoubleSpinBox" name="latitudeDoubleSpinBox">
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-90.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>90.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Longitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Icon Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Latitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QToolButton" name="iconFileOpenButton">
|
||||
<property name="toolTip">
|
||||
<string>Add Custom Icon</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QDoubleSpinBox" name="longitudeDoubleSpinBox">
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-180.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>180.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QLineEdit" name="nameLineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QComboBox" name="iconComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue