Skip to content

Commit

Permalink
Merge pull request #1578 from ghutchis/set-tool-icons
Browse files Browse the repository at this point in the history
Update tool plugins to set icon as light / dark theme
  • Loading branch information
ghutchis authored Jan 18, 2024
2 parents 12db5d8 + 350d18d commit d6acfd6
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 33 deletions.
5 changes: 5 additions & 0 deletions avogadro/qtgui/toolplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class AVOGADROQTGUI_EXPORT ToolPlugin : public QObject
*/
virtual QAction* activateAction() const = 0;

/**
* Set the tool icon (based on dark / light theme).
*/
virtual void setIcon(bool darkTheme = false) = 0;

/**
* @return A QWidget that will be displayed to the user while this tool is
* active.
Expand Down
10 changes: 9 additions & 1 deletion avogadro/qtplugins/aligntool/aligntool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ AlignTool::AlignTool(QObject* parent_)
m_alignType(0), m_axis(0)
{
m_activateAction->setText(tr("Align"));
m_activateAction->setIcon(QIcon(":/icons/align_light.svg"));
m_activateAction->setToolTip(
tr("Align Molecules\n\n"
"Left Mouse: \tSelect up to two atoms.\n"
"\tThe first atom is centered at the origin.\n"
"\tThe second atom is aligned to the selected axis.\n"
"Right Mouse: \tReset alignment.\n"
"Double-Click: \tCenter the atom at the origin."));
setIcon();
}

AlignTool::~AlignTool()
Expand All @@ -67,6 +67,14 @@ AlignTool::~AlignTool()
m_toolWidget->deleteLater();
}

void AlignTool::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/align_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/align_light.svg"));
}

QWidget* AlignTool::toolWidget() const
{
if (!m_toolWidget) {
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/aligntool/aligntool.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class AlignTool : public QtGui::ToolPlugin
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;

void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule* mol) override
{
if (mol)
Expand Down
10 changes: 9 additions & 1 deletion avogadro/qtplugins/bondcentrictool/bondcentrictool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ BondCentricTool::BondCentricTool(QObject* parent_)
m_planeSnapIncr(10.f), m_snapPlaneToBonds(true)
{
m_activateAction->setText(tr("Bond-Centric Manipulation"));
m_activateAction->setIcon(QIcon(":/icons/bondcentric_light.svg"));
m_activateAction->setToolTip(
tr("Bond Centric Manipulation Tool\n\n"
"Left Mouse: \tClick and drag to rotate the view.\n"
Expand All @@ -129,10 +128,19 @@ BondCentricTool::BondCentricTool(QObject* parent_)
"Left Click & Drag on a Bond to set the Manipulation Plane:\n"
"Left Click & Drag one of the Atoms in the Bond to change the angle\n"
"Right Click & Drag one of the Atoms in the Bond to change the length"));
setIcon();
}

BondCentricTool::~BondCentricTool() {}

void BondCentricTool::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/bondcentric_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/bondcentric_light.svg"));
}

QWidget* BondCentricTool::toolWidget() const
{
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/bondcentrictool/bondcentrictool.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BondCentricTool : public QtGui::ToolPlugin
unsigned char priority() const override { return 40; }
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;
void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule*) override;
void setEditMolecule(QtGui::RWMolecule*) override;
Expand Down
12 changes: 10 additions & 2 deletions avogadro/qtplugins/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include <avogadro/rendering/textlabel3d.h>
#include <avogadro/rendering/textproperties.h>

#include <QAction>
#include <QtGui/QGuiApplication>
#include <QtGui/QIcon>
#include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QWheelEvent>
#include <QAction>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QWidget>

Expand Down Expand Up @@ -69,16 +69,24 @@ Editor::Editor(QObject* parent_)
m_fixValenceLater(false), m_layerManager("Editor")
{
m_activateAction->setText(tr("Draw"));
m_activateAction->setIcon(QIcon(":/icons/editor_light.svg"));
m_activateAction->setToolTip(
tr("Draw Tool\n\n"
"Left Mouse: \tClick and Drag to create Atoms and Bond\n"
"Right Mouse: \tDelete Atom"));
setIcon();
reset();
}

Editor::~Editor() {}

void Editor::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/editor_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/editor_light.svg"));
}

QWidget* Editor::toolWidget() const
{
return m_toolWidget;
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Editor : public QtGui::ToolPlugin
unsigned char priority() const override { return 20; }
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;
void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule* mol) override
{
Expand Down
14 changes: 11 additions & 3 deletions avogadro/qtplugins/label/labeleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <avogadro/rendering/primitive.h>
#include <avogadro/rendering/textlabel3d.h>

#include <QKeyEvent>
#include <QAction>
#include <QKeyEvent>

namespace Avogadro::QtPlugins {

Expand All @@ -27,14 +27,22 @@ LabelEditor::LabelEditor(QObject* parent_)
m_selected(false), m_text("")
{
m_activateAction->setText(tr("Edit Labels"));
m_activateAction->setIcon(QIcon(":/icons/label_light.svg"));
m_activateAction->setToolTip(
tr("Atom Label Tool\n\n"
"Left Mouse: \tClick on Atoms to add Custom Labels"));
setIcon();
}

LabelEditor::~LabelEditor() {}

void LabelEditor::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/label_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/label_light.svg"));
}

QUndoCommand* LabelEditor::mouseReleaseEvent(QMouseEvent*)
{
return nullptr;
Expand Down Expand Up @@ -130,4 +138,4 @@ void LabelEditor::draw(Rendering::GroupNode& node)
TextLabel3D* atomLabel = createLabel(m_text.toStdString(), pos, radius);
geometry->addDrawable(atomLabel);
}
} // namespace Avogadro
} // namespace Avogadro::QtPlugins
1 change: 1 addition & 0 deletions avogadro/qtplugins/label/labeleditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LabelEditor : public QtGui::ToolPlugin
QString description() const override { return tr("Label editor tool"); }
unsigned char priority() const override { return 25; }
QAction* activateAction() const override { return m_activateAction; }
void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule* mol) override
{
Expand Down
11 changes: 9 additions & 2 deletions avogadro/qtplugins/manipulator/manipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@ Manipulator::Manipulator(QObject* parent_)
m_currentAction(Nothing)
{
m_activateAction->setText(tr("Manipulate"));
m_activateAction->setIcon(QIcon(":/icons/manipulator_light.svg"));
m_activateAction->setToolTip(
tr("Manipulation Tool\n\n"
"Left Mouse: \tClick and drag to move atoms\n"
"Right Mouse: \tClick and drag to rotate selected atoms.\n"));

setIcon();
connect(m_toolWidget->buttonBox, SIGNAL(clicked(QAbstractButton*)), this,
SLOT(buttonClicked(QAbstractButton*)));
}

Manipulator::~Manipulator() {}

void Manipulator::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/manipulator_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/manipulator_light.svg"));
}

QWidget* Manipulator::toolWidget() const
{
return m_toolWidget;
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/manipulator/manipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Manipulator : public QtGui::ToolPlugin
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;

void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule* mol) override
{
if (mol)
Expand Down
14 changes: 11 additions & 3 deletions avogadro/qtplugins/measuretool/measuretool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

#include <avogadro/core/angletools.h>

#include <QAction>
#include <QtGui/QGuiApplication>
#include <QtGui/QIcon>
#include <QtGui/QMouseEvent>
#include <QAction>

#include <QDebug>

Expand All @@ -52,18 +52,26 @@ MeasureTool::MeasureTool(QObject* parent_)
m_molecule(nullptr), m_rwMolecule(nullptr), m_renderer(nullptr)
{
m_activateAction->setText(tr("Measure"));
m_activateAction->setIcon(QIcon(":/icons/measure_light.svg"));
m_activateAction->setToolTip(
tr("Measure Tool\n\n"
"Left Mouse: \tSelect up to four Atoms.\n"
"\tDistances are measured between 1-2 and 2-3\n"
"\tAngle is measured between 1-3 using 2 as the common point\n"
"\tDihedral is measured between 1-2-3-4\n"
"Right Mouse: \tReset the measurements."));
setIcon();
}

MeasureTool::~MeasureTool() {}

void MeasureTool::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/measure_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/measure_light.svg"));
}

QWidget* MeasureTool::toolWidget() const
{
return nullptr;
Expand Down Expand Up @@ -279,4 +287,4 @@ bool MeasureTool::toggleAtom(const Rendering::Identifier& atom)
return true;
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
3 changes: 2 additions & 1 deletion avogadro/qtplugins/measuretool/measuretool.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MeasureTool : public QtGui::ToolPlugin
unsigned char priority() const override { return 60; }
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;
void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule*) override;
void setEditMolecule(QtGui::RWMolecule*) override;
Expand All @@ -49,7 +50,7 @@ class MeasureTool : public QtGui::ToolPlugin
private:
Vector3ub contrastingColor(const Vector3ub& rgb) const;
bool toggleAtom(const Rendering::Identifier& atom);
template<typename T>
template <typename T>
void createLabels(T* mol, Rendering::GeometryNode* geo,
QVector<Vector3>& positions);

Expand Down
11 changes: 9 additions & 2 deletions avogadro/qtplugins/navigator/navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,24 @@ Navigator::Navigator(QObject* parent_)
m_currentAction(Nothing)
{
m_activateAction->setText(tr("Navigate"));
m_activateAction->setIcon(QIcon(":/icons/navigator_light.svg"));
m_activateAction->setToolTip(
tr("Navigation Tool\n\n"
"Left Mouse: \tClick and drag to rotate the view.\n"
"Middle Mouse: \tClick and drag to zoom in or out.\n"
"Right Mouse: \tClick and drag to move the view.\n"));

setIcon();
QSettings settings;
m_zoomDirection = settings.value("navigator/zoom", 1).toInt();
}

void Navigator::setIcon(bool darkTheme)
{
if (darkTheme)
m_activateAction->setIcon(QIcon(":/icons/navigator_dark.svg"));
else
m_activateAction->setIcon(QIcon(":/icons/navigator_light.svg"));
}

void Navigator::registerCommands()
{
emit registerCommand("rotateScene",
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/navigator/navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Navigator : public QtGui::ToolPlugin
unsigned char priority() const override { return 10; }
QAction* activateAction() const override { return m_activateAction; }
QWidget* toolWidget() const override;
void setIcon(bool darkTheme = false) override;

void setMolecule(QtGui::Molecule* mol) override { m_molecule = mol; }
void setGLWidget(QtOpenGL::GLWidget* widget) override { m_glWidget = widget; }
Expand Down
Loading

0 comments on commit d6acfd6

Please sign in to comment.