Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update render options #700

Merged
merged 4 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions avogadro/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ configure_file("${CMAKE_CURRENT_BINARY_DIR}/avogadropython.h.in"

set(HEADERS
backgroundfileformat.h
colorbutton.h
containerwidget.h
customelementdialog.h
elementtranslator.h
Expand Down Expand Up @@ -62,6 +63,7 @@ set(HEADERS

set(SOURCES
backgroundfileformat.cpp
colorbutton.cpp
containerwidget.cpp
customelementdialog.cpp
elementdetail_p.cpp
Expand Down
90 changes: 90 additions & 0 deletions avogadro/qtgui/colorbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

// Adapted from Avogadro 1.0 by Geoffrey Hutchison
// Contributed to Avogadro 2.0 by Geoffrey Hutchison

#include "colorbutton.h"

#include <QColorDialog>
#include <QPainter>

namespace Avogadro {
namespace QtGui {

ColorButton::ColorButton(QWidget* parent)
: QAbstractButton(parent), m_color(Qt::white), m_title("")
{
setMinimumSize(35, 20);

connect(this, SIGNAL(clicked()), this, SLOT(changeColor()));
}

ColorButton::ColorButton(const QColor& initial, QWidget* parent)
: QAbstractButton(parent), m_color(initial)
{
setMinimumSize(35, 20);

connect(this, SIGNAL(clicked()), this, SLOT(changeColor()));
}

void ColorButton::changeColor()
{
// This could be an ifdef for KColorDialog if KDE is present
if (m_title == "")
m_color = QColorDialog::getColor(m_color, this);
else
m_color = QColorDialog::getColor(m_color, this, m_title);
update();

emit colorChanged(m_color);
}

void ColorButton::setColor(const QColor& color)
{
m_color = color;
update();

emit colorChanged(m_color);
}

void ColorButton::setDialogTitle(const QString title)
{
m_title = title;
}

QColor ColorButton::color() const
{
return m_color;
}

void ColorButton::paintEvent(QPaintEvent*)
{
// TODO: If we go to RGBA colors, we should really show two pieces
// e.g. -----------
// | /|
// | non / |
// | alpha/ |
// | / |
// | /alpha
// | / |
// -----------

QPainter painter(this);

// outer border
painter.drawRect(0, 0, width(), height());
// inner color
painter.setBrush(m_color);
painter.drawRect(4, 4, width() - 8, height() - 8);
}

bool ColorButton::event(QEvent* e)
{
return QAbstractButton::event(e);
}

} // namespace QtGui
} // namespace Avogadro
86 changes: 86 additions & 0 deletions avogadro/qtgui/colorbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the 3-Clause BSD License, (see "LICENSE").
******************************************************************************/

// Adapted from Avogadro 1.0 by Geoffrey Hutchison
// Contributed to Avogadro 2.0 by Geoffrey Hutchison

#ifndef AVOGADRO_QTGUI_COLORBUTTON_H
#define AVOGADRO_QTGUI_COLORBUTTON_H

#include "avogadroqtguiexport.h"

#include <QAbstractButton>
#include <QColor>

namespace Avogadro {
namespace QtGui {

/**
* @class ColorButton colorbutton.h <avogadro/colorbutton.h>
* @author Geoffrey Hutchison
* @brief A button to show the current color and bring up the QColorDialog.
*
* This class implements a QAbstractButton to display a colored rectangle.
* When clicked by the user, it brings up a color picker to select a new
* color.
*
* The widget has a default minimium size of 35x20 pixels.
*/

class AVOGADROQTGUI_EXPORT ColorButton : public QAbstractButton
{
Q_OBJECT

public:
ColorButton(QWidget* parent = 0);
explicit ColorButton(const QColor& initial, QWidget* parent = 0);

/**
* Redraw the widget (i.e., refresh the colored rectange)
*/
void paintEvent(QPaintEvent*);

/**
* @param color the new color to be used
*/
void setColor(const QColor& color);

/**
* @param custom title for color choice dialog
*/
void setDialogTitle(const QString title = "");

/**
* @return the current color
*/
QColor color() const;

Q_SIGNALS:
/**
* emit any time the color is changed, either by a user or by setColor()
*/
void colorChanged(const QColor &);

public Q_SLOTS:
/**
* Call for a change in the current color
*/
void changeColor();

protected:
/**
* Generic event handler, currently defaults to calling parent class
* (included for future compatibility)
*/
bool event(QEvent* e);

QColor m_color; //!< The current color
QString m_title; //!< The current dialog title
};

} // namespace QtGui
} // namespace Avogadro

#endif
26 changes: 19 additions & 7 deletions avogadro/qtplugins/ballandstick/ballandstick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <avogadro/rendering/groupnode.h>
#include <avogadro/rendering/spheregeometry.h>

#include <QtCore/QSettings>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QDoubleSpinBox>
#include <QtWidgets/QHBoxLayout>
Expand All @@ -36,15 +37,17 @@ namespace QtPlugins {

using Core::Elements;
using Core::Molecule;
using Rendering::CylinderGeometry;
using Rendering::GeometryNode;
using Rendering::GroupNode;
using Rendering::SphereGeometry;
using Rendering::CylinderGeometry;

BallAndStick::BallAndStick(QObject* p)
: ScenePlugin(p), m_enabled(true), m_group(nullptr), m_setupWidget(nullptr),
m_multiBonds(true), m_showHydrogens(true)
: ScenePlugin(p), m_enabled(true), m_group(nullptr), m_setupWidget(nullptr)
{
QSettings settings;
m_multiBonds = settings.value("ballandstick/multiBonds", true).toBool();
m_showHydrogens = settings.value("ballandstick/showHydrogens", true).toBool();
}

BallAndStick::~BallAndStick()
Expand Down Expand Up @@ -204,14 +207,18 @@ QWidget* BallAndStick::setupWidget()
if (!m_setupWidget) {
m_setupWidget = new QWidget(qobject_cast<QWidget*>(parent()));
QVBoxLayout* v = new QVBoxLayout;
QCheckBox* check = new QCheckBox(tr("Show multiple bonds?"));

QCheckBox* check = new QCheckBox(tr("Show multiple bonds"));
check->setChecked(m_multiBonds);
connect(check, SIGNAL(clicked(bool)), SLOT(multiBonds(bool)));
v->addWidget(check);
check = new QCheckBox(tr("Show hydrogens?"));

check = new QCheckBox(tr("Show hydrogens"));
check->setChecked(m_showHydrogens);
connect(check, SIGNAL(toggled(bool)), SLOT(showHydrogens(bool)));
v->addWidget(check);

v->addStretch(1);
m_setupWidget->setLayout(v);
}
return m_setupWidget;
Expand All @@ -223,6 +230,8 @@ void BallAndStick::multiBonds(bool show)
m_multiBonds = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("BallAndStick/multiBonds", show);
}

void BallAndStick::showHydrogens(bool show)
Expand All @@ -231,6 +240,9 @@ void BallAndStick::showHydrogens(bool show)
m_showHydrogens = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("BallAndStick/showHydrogens", show);
}
}
}

} // namespace QtPlugins
} // namespace Avogadro
41 changes: 33 additions & 8 deletions avogadro/qtplugins/cartoons/cartoons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "cartoons.h"

#include <QtCore/QSettings>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
Expand All @@ -31,8 +32,8 @@ using Core::Atom;
using Core::AtomicNumber;
using Core::Elements;
using Core::Molecule;
using Rendering::BezierGeometry;
using Rendering::BSplineGeometry;
using Rendering::BezierGeometry;
using Rendering::Cartoon;
using Rendering::CylinderGeometry;
using Rendering::GeometryNode;
Expand Down Expand Up @@ -61,10 +62,16 @@ typedef list<BackboneResidue> AtomsPairList;

Cartoons::Cartoons(QObject* parent)
: ScenePlugin(parent), m_group(nullptr), m_setupWidget(nullptr),
m_enabled(true), m_showBackbone(true), m_showTrace(false),
m_showTube(false), m_showRibbon(false), m_showRope(false),
m_showCartoon(true)
{}
m_enabled(true)
{
QSettings settings;
m_showBackbone = settings.value("cartoon/backbone", true).toBool();
m_showCartoon = settings.value("cartoon/cartoon", true).toBool();
m_showTrace = settings.value("cartoon/trace", false).toBool();
m_showTube = settings.value("cartoon/tube", false).toBool();
m_showRibbon = settings.value("cartoon/ribbon", false).toBool();
m_showRope = settings.value("cartoon/rope", false).toBool();
}

Cartoons::~Cartoons()
{
Expand Down Expand Up @@ -299,8 +306,12 @@ QWidget* Cartoons::setupWidget()
m_setupWidget = new QWidget(qobject_cast<QWidget*>(parent()));
QVBoxLayout* v = new QVBoxLayout;
QStringList boxesText;
boxesText << tr("Backbone") << tr("Trace") << tr("Tube") << tr("Ribbon")
<< tr("Cartoon") << tr("Rope");
boxesText << tr("Backbone", "protein rendering style")
<< tr("Trace", "protein rendering style")
<< tr("Tube", "protein rendering style")
<< tr("Ribbon", "protein rendering style")
<< tr("Cartoon", "protein rendering style")
<< tr("Rope", "protein rendering style");
vector<reference_wrapper<bool>> boxesBools = { m_showBackbone, m_showTrace,
m_showTube, m_showRibbon,
m_showCartoon, m_showRope };
Expand All @@ -310,13 +321,15 @@ QWidget* Cartoons::setupWidget()
m_jumpTable[3] = &Cartoons::showRibbon;
m_jumpTable[4] = &Cartoons::showCartoon;
m_jumpTable[5] = &Cartoons::showRope;
for (size_t i = 0; i < 6; ++i) {
for (size_t i = 0; i < boxesText.size(); ++i) {
QCheckBox* check = new QCheckBox(boxesText[i]);
check->setChecked(boxesBools[i]);
connect(check, &QCheckBox::clicked, this, m_jumpTable[i]);
v->addWidget(check);
}

// make sure there's empty space at the bottom,s otherwise the
v->addStretch(1);
m_setupWidget->setLayout(v);
}
return m_setupWidget;
Expand All @@ -328,6 +341,8 @@ void Cartoons::showBackbone(bool show)
m_showBackbone = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/backbone", show);
}

void Cartoons::showTrace(bool show)
Expand All @@ -336,6 +351,8 @@ void Cartoons::showTrace(bool show)
m_showTrace = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/trace", show);
}

void Cartoons::showTube(bool show)
Expand All @@ -344,6 +361,8 @@ void Cartoons::showTube(bool show)
m_showTube = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/tube", show);
}

void Cartoons::showRibbon(bool show)
Expand All @@ -352,6 +371,8 @@ void Cartoons::showRibbon(bool show)
m_showRibbon = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/ribbon", show);
}

void Cartoons::showCartoon(bool show)
Expand All @@ -360,6 +381,8 @@ void Cartoons::showCartoon(bool show)
m_showCartoon = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/cartoon", show);
}

void Cartoons::showRope(bool show)
Expand All @@ -368,6 +391,8 @@ void Cartoons::showRope(bool show)
m_showRope = show;
emit drawablesChanged();
}
QSettings settings;
settings.setValue("cartoon/rope", show);
}

} // namespace QtPlugins
Expand Down
Loading