Commit 0fcaa9a1 authored by Malte Jürgens's avatar Malte Jürgens Committed by Albert Astals Cid
Browse files

Configurable Isotope Table View Modes

parent f3bc9def
Pipeline #163505 passed with stage
in 2 minutes and 26 seconds
......@@ -146,8 +146,14 @@ set(kalzium_SRCS
tableinfowidget.h
tablesdialog.cpp
tablesdialog.h
unitsettingsdialog.cpp
unitsettingsdialog.h
settings/kalziumconfigdialog.cpp
settings/kalziumconfigdialog.h
settings/unitsettingsdialog.cpp
settings/unitsettingsdialog.h
settings/isotopetablesettingsdialog.cpp
settings/isotopetablesettingsdialog.h
settings/isotopetablesettingscard.cpp
settings/isotopetablesettingscard.h
)
if (LIBFACILE_FOUND)
......@@ -166,17 +172,17 @@ endif (LIBFACILE_FOUND)
ki18n_wrap_ui(kalzium_SRCS
isotopetable/isotopedialog.ui
settings_colors.ui
plotsetupwidget.ui
molcalcwidgetbase.ui
spectrumview.ui
settings_gradients.ui
rswidget.ui
gradientwidget.ui
exportdialog.ui
settings/settings_colors.ui
settings/settings_gradients.ui
)
kconfig_add_kcfg_files(kalzium_SRCS prefs.kcfgc )
kconfig_add_kcfg_files(kalzium_SRCS GENERATE_MOC prefs.kcfgc )
#kde4_add_app_icon(kalzium_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-kalzium.png")
......@@ -238,7 +244,7 @@ install(TARGETS kalzium ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
########### install files ###############
install(PROGRAMS org.kde.kalzium.desktop org.kde.kalzium_cml.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES kalzium.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES settings/kalzium.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kalziumui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kalzium)
ecm_install_icons(ICONS
......
......@@ -24,11 +24,8 @@ void IsotopeGuideView::setGuidedView(IsotopeView *guidedView)
this, &IsotopeGuideView::setZoomLevel);
connect(m_guidedView, &IsotopeView::visibleSceneRectChanged,
this, &IsotopeGuideView::setVisibleSceneRect);
m_zoomLevel = m_guidedView->zoomLevel();
setScene(m_guidedView->scene());
setSceneRect(scene()->itemsBoundingRect());
ensureVisible(scene()->sceneRect());
updateScene();
}
void IsotopeGuideView::setVisibleSceneRect(const QPolygonF& sceneRect)
......@@ -41,7 +38,7 @@ void IsotopeGuideView::drawForeground(QPainter *painter, const QRectF &rect)
{
if (m_guidedView && m_visibleSceneRect.boundingRect().intersects(rect)) {
QRectF drawRect = m_visibleSceneRect.boundingRect().adjusted(0, 0, -1, -1);
painter->setPen(QPen(Qt::yellow, 10.0));
painter->setPen(QPen(Qt::yellow, 1.0 / m_scale));
painter->fillRect(drawRect, QBrush(QColor(0, 0 , 0 , 100)));
painter->drawRect(drawRect);
}
......@@ -50,8 +47,8 @@ void IsotopeGuideView::drawForeground(QPainter *painter, const QRectF &rect)
void IsotopeGuideView::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event)
m_scale = qMin(qreal(viewport()->width()) / scene()->width(),
qreal(viewport()->height()) / scene()->height());
m_scale = qMin(qreal(viewport()->width()) / sceneRect().width(),
qreal(viewport()->height()) / sceneRect().height());
setTransform(QTransform::fromScale(m_scale, m_scale));
}
......@@ -92,3 +89,12 @@ void IsotopeGuideView::setZoomLevel(double zoomLevel)
m_zoomLevel = zoomLevel;
}
void IsotopeGuideView::updateScene()
{
m_zoomLevel = m_guidedView->zoomLevel();
setScene(m_guidedView->scene());
setSceneRect(scene()->itemsBoundingRect());
ensureVisible(scene()->sceneRect());
resizeEvent(nullptr);
}
......@@ -37,6 +37,9 @@ private:
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
public Q_SLOTS:
void updateScene();
private Q_SLOTS:
void setZoomLevel(double zoomLevel);
void setVisibleSceneRect(const QPolygonF &sceneRect);
......
......@@ -12,15 +12,15 @@
#include <element.h>
#include <isotope.h>
IsotopeScene::IsotopeScene(QObject *parent) : QGraphicsScene(parent)
IsotopeScene::IsotopeScene(QObject *parent, int mode) : QGraphicsScene(parent)
{
m_mode = mode;
m_isotopeGroup = new QGraphicsItemGroup();
m_isotopeGroup->setHandlesChildEvents(false);
addItem(m_isotopeGroup);
m_itemSize = 10;
drawIsotopes();
//m_isotopeGroup->scale(-1, 1);
}
IsotopeScene::~IsotopeScene()
......@@ -36,8 +36,12 @@ void IsotopeScene::updateContextHelp(IsotopeItem * item)
void IsotopeScene::drawIsotopes()
{
for (auto item : m_isotopeGroup->childItems()) {
m_isotopeGroup->removeFromGroup(item);
delete item;
}
const QList<Element*> elist = KalziumDataObject::instance()->ElementList;
int mode = 0;
foreach (Element *e, elist) {
int elementNumber = e->dataAsVariant(ChemicalDataObject::atomicNumber).toInt();
......@@ -47,26 +51,23 @@ void IsotopeScene::drawIsotopes()
int x = elementNumber * m_itemSize;
int y = (300 - i->nucleons()) * m_itemSize;
if (mode == 0) {
//One part to the side of the other
if (m_mode == 0) {
// One part to the side of the other
int threshold = 60;
if (elementNumber > threshold) {
y += 120 * m_itemSize;
x += 5 * m_itemSize;
}
} else if (mode == 1) {
//one part above the other part
int threshold = 0;
if (elementNumber > threshold) {
y -= 20 * m_itemSize;
x -= threshold * m_itemSize;
}
} else if (mode == 2) {
//Both parts continuous
} else if (mode == 3) {
//Horizontally
} else if (m_mode == 1) {
// Both parts continuous
} else if (m_mode == 2) {
// Horizontally
y = (elist.count() - elementNumber) * m_itemSize;
x = i->nucleons() * m_itemSize;
} else if (m_mode == 3) {
// Horizontally (shifted)
y = (elist.count() - elementNumber) * m_itemSize;
x = (i->nucleons() - elementNumber) * m_itemSize;
}
IsotopeItem *item = new IsotopeItem(i, x, y, m_itemSize,m_itemSize);
......@@ -75,3 +76,8 @@ void IsotopeScene::drawIsotopes()
}
}
void IsotopeScene::setMode(int mode) {
m_mode = mode;
drawIsotopes();
}
......@@ -16,22 +16,35 @@ class IsotopeScene : public QGraphicsScene
Q_OBJECT
public:
explicit IsotopeScene(QObject * parent = nullptr);
explicit IsotopeScene(QObject * parent, int mode);
virtual ~IsotopeScene();
void updateContextHelp(IsotopeItem * item);
private:
void initialize();
private:
void drawIsotopes(void);
//the size of each item
int m_itemSize;
int m_mode;
///this group stores all IsotopeItems
QGraphicsItemGroup *m_isotopeGroup;
signals:
public:
int mode() const {
return m_mode;
}
Q_SIGNALS:
void itemSelected(IsotopeItem *item);
public:
void setMode(int mode);
};
#endif // ISOTOPESCENE_H
......@@ -103,3 +103,11 @@ void IsotopeTableDialog::slotZoomLevelChanged(double value)
ui.Slider->blockSignals(b);
}
void IsotopeTableDialog::setMode(int mode) {
ui.gv->setMode(mode);
ui.guide->updateScene();
}
void IsotopeTableDialog::updateMode() {
setMode(Prefs::isotopeTableMode());
}
......@@ -29,6 +29,10 @@ public:
private:
Ui::isotopeWidget ui;
public Q_SLOTS:
void setMode(int mode);
void updateMode();
private Q_SLOTS:
void updateDockWidget(IsotopeItem *);
void zoom(int);
......
......@@ -7,19 +7,32 @@
#include "isotopeview.h"
#include "isotopescene.h"
#include "prefs.h"
IsotopeView::IsotopeView(QWidget *parent) : QGraphicsView(parent)
{
m_scene = new IsotopeScene(this);
m_scene = new IsotopeScene(this, Prefs::isotopeTableMode());
m_zoomLevel = 1.0;
initialize();
}
IsotopeView::IsotopeView(QWidget *parent, int mode) : QGraphicsView(parent)
{
m_scene = new IsotopeScene(this, mode);
m_zoomLevel = 1.0;
initialize();
}
void IsotopeView::initialize()
{
setScene(m_scene);
setSceneRect(m_scene->itemsBoundingRect());
// Center the bottom left at the beginning
// centerOn(0, sceneRect().height());
// Zoom in a bit
// setZoom(3);
// Zoom in a bit
setZoom(0.3);
// Makes sure that you always zoom to the mouse if you use the scroll wheel
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
QPolygonF visibleSceneRect = mapToScene(viewport()->rect());
Q_EMIT visibleSceneRectChanged(visibleSceneRect);
}
IsotopeView::~IsotopeView()
......@@ -29,10 +42,13 @@ IsotopeView::~IsotopeView()
void IsotopeView::resizeEvent(QResizeEvent *event)
{
//ensureVisible(QRectF(0,0,100,100),0,0);
//event->accept();
event->ignore();
Q_UNUSED(event)
if (!isInteractive())
{
qreal scale = qMin(qreal(viewport()->width()) / sceneRect().width(),
qreal(viewport()->height()) / sceneRect().height());
setTransform(QTransform::fromScale(scale, scale));
}
}
void IsotopeView::mouseMoveEvent(QMouseEvent *event)
......@@ -45,17 +61,27 @@ void IsotopeView::mouseMoveEvent(QMouseEvent *event)
void IsotopeView::wheelEvent(QWheelEvent *event)
{
if (!isInteractive())
{
event->accept();
return;
}
double oldZoomLevel = m_zoomLevel;
double factor = event->angleDelta().y() / 1000.0;
m_zoomLevel = oldZoomLevel + oldZoomLevel * factor;
if (m_zoomLevel < 0.3) {
if (m_zoomLevel < 0.3)
{
m_zoomLevel = 0.3;
} else if (m_zoomLevel > 10.0) {
}
else if (m_zoomLevel > 10.0)
{
m_zoomLevel = 10.0;
}
if (oldZoomLevel != m_zoomLevel) {
if (oldZoomLevel != m_zoomLevel)
{
factor = m_zoomLevel / oldZoomLevel;
scale(factor, factor);
Q_EMIT zoomLevelChanged(m_zoomLevel);
......@@ -73,15 +99,29 @@ void IsotopeView::setZoom(double zoom)
m_zoomLevel = zoom;
if (m_zoomLevel < 0.3) {
if (m_zoomLevel < 0.3 && isInteractive())
{
m_zoomLevel = 0.3;
} else if (m_zoomLevel > 10.0) {
}
else if (m_zoomLevel > 10.0 && isInteractive())
{
m_zoomLevel = 10.0;
}
factor = m_zoomLevel / oldZoomLevel;
scale(factor,factor);
scale(factor, factor);
Q_EMIT zoomLevelChanged(m_zoomLevel);
QPolygonF visibleSceneRect = mapToScene(viewport()->rect());
Q_EMIT visibleSceneRectChanged(visibleSceneRect);
}
int IsotopeView::mode() const
{
return m_scene->mode();
}
void IsotopeView::setMode(int mode)
{
m_scene->setMode(mode);
initialize();
}
......@@ -19,11 +19,16 @@ class IsotopeView : public QGraphicsView
public:
explicit IsotopeView(QWidget *parent = nullptr);
explicit IsotopeView(QWidget *parent, int mode);
~IsotopeView() override;
private:
void initialize();
private:
IsotopeScene *m_scene;
double m_zoomLevel;
int m_mode;
public:
double zoomLevel() {
......@@ -33,12 +38,16 @@ public:
return mapToScene(viewport()->rect());
}
signals:
Q_SIGNALS:
void zoomLevelChanged(double zoomLevel);
void visibleSceneRectChanged(const QPolygonF &sceneRect);
public:
public Q_SLOTS:
void setZoom(double zoom);
void setMode(int mode);
public:
int mode() const;
protected:
void resizeEvent(QResizeEvent *event) override;
......
......@@ -8,9 +8,6 @@
#include <element.h>
#include <kdeeduglossary.h>
#include "prefs.h"
#include "ui_settings_colors.h"
#include "ui_settings_gradients.h"
#include "ui_settings_calc.h"
#include "detailinfodlg.h"
#include "detailedgraphicaloverview.h"
#include "gradientwidget_impl.h"
......@@ -52,7 +49,6 @@
#include <QUrl>
#include <KActionCollection>
#include <KConfigDialog>
#include <KLocalizedString>
#include <KPluginLoader>
#include <KSelectAction>
......@@ -398,10 +394,11 @@ void Kalzium::slotTables()
void Kalzium::slotIsotopeTable()
{
if (!m_isotopeDialog) {
m_isotopeDialog = new IsotopeTableDialog(this);
}
m_isotopeDialog->show();
if (!m_isotopeDialog) {
m_isotopeDialog = new IsotopeTableDialog(this);
connect(Prefs::self(), &Prefs::isotopeTableModeChanged, m_isotopeDialog, &IsotopeTableDialog::updateMode);
}
m_isotopeDialog->show();
}
void Kalzium::slotPlotData()
......@@ -479,53 +476,21 @@ void Kalzium::slotSwitchtoLookScheme(int which)
void Kalzium::showSettingsDialog()
{
if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
if (KalziumConfigDialog::showDialog(QStringLiteral("settings"))) {
return;
}
//KConfigDialog didn't find an instance of this dialog, so lets create it :
KConfigDialog *dialog = new KConfigDialog(this,QStringLiteral("settings"), Prefs::self());
// colors page
Ui_setupColors ui_colors;
QWidget *w_colors = new QWidget(this);
w_colors->setObjectName(QStringLiteral("colors_page"));
ui_colors.setupUi(w_colors);
dialog->addPage(w_colors, i18n("Schemes"), QStringLiteral("preferences-desktop-color"));
// gradients page
Ui_setupGradients ui_gradients;
QWidget *w_gradients = new QWidget(this);
w_gradients->setObjectName(QStringLiteral("gradients_page"));
ui_gradients.setupUi(w_gradients);
dialog->addPage(w_gradients, i18n("Gradients"), QStringLiteral("preferences-desktop-color"));
// units page
m_unitsDialog = new UnitSettingsDialog(this);
m_unitsDialog->setObjectName(QStringLiteral("units_page"));
dialog->addPage(m_unitsDialog, i18n("Units"), QStringLiteral("system-run"));
Ui_setupCalc ui_calc;
QWidget *w_calc = new QWidget(this);
ui_calc.setupUi(w_calc);
dialog->addPage(w_calc, i18n("Calculator"), QStringLiteral("accessories-calculator"));
connect(dialog, &KConfigDialog::settingsChanged, this, &Kalzium::slotUpdateSettings);
connect(dialog, &KConfigDialog::settingsChanged, m_gradientWidget, &GradientWidgetImpl::slotGradientChanged);
dialog->show();
//KalziumConfigDialog didn't find an instance of this dialog, so lets create it :
m_configDialog = new KalziumConfigDialog(this,QStringLiteral("settings"), Prefs::self());
connect(m_configDialog, &KalziumConfigDialog::settingsChanged, this, &Kalzium::slotUpdateSettings);
connect(m_configDialog, &KalziumConfigDialog::settingsChanged, m_gradientWidget, &GradientWidgetImpl::slotGradientChanged);
m_configDialog->show();
}
void Kalzium::slotUpdateSettings()
{
Prefs::setLengthUnit(m_unitsDialog->getLenghtUnitId());
Prefs::setEnergiesUnit(m_unitsDialog->getEnergyUnitId());
Prefs::setTemperatureUnit(m_unitsDialog->getTemperatureUnitId());
Prefs::self()->save();
/*This slot function calls change the color of pse elements immediately after prefs change*/
slotSwitchtoLookGradient(Prefs::colorgradientbox());
slotSwitchtoLookScheme(Prefs::colorschemebox());
......
......@@ -8,7 +8,7 @@
#include <kxmlguiwindow.h>
#include "periodictableview.h"
#include "unitsettingsdialog.h"
#include "settings/kalziumconfigdialog.h"
#include "isotopetabledialog.h"
#include "elementdataviewer.h"
#include "tablesdialog.h"
......@@ -127,7 +127,7 @@ private:
ExportDialog *m_exportDialog;
UnitSettingsDialog *m_unitsDialog;
KalziumConfigDialog *m_configDialog;
QLabel *m_elementInfo;
......
# Code generation options for kconfig_compiler
File=kalzium.kcfg
File=settings/kalzium.kcfg
#IncludeFiles=defines.h
ClassName=Prefs
Singleton=true
Mutators=true
DefaultValueGetters=true
/*
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "isotopetablesettingscard.h"
#include <QVBoxLayout>
#include <iostream>
IsotopeTableSettingsCard::IsotopeTableSettingsCard(QWidget* parent, int mode): QFrame(parent)
{
m_isotopeView = new IsotopeView(this, mode);
initialize();
}
IsotopeTableSettingsCard::IsotopeTableSettingsCard(QWidget* parent): QFrame(parent)
{
m_isotopeView = new IsotopeView(this);
initialize();
}
void IsotopeTableSettingsCard::initialize() {
QVBoxLayout *vLayout = new QVBoxLayout();
m_isotopeView->setInteractive(false);
m_isotopeView->setZoom(0.06);
// m_isotopeView->setMaximumWidth(200);
// m_isotopeView->setMaximumHeight(150);
m_radioButton = new QRadioButton();
m_radioButton->setText("Next to each other");
connect(m_radioButton, &QRadioButton::toggled, this, [=](){
if (m_radioButton->isChecked())
emit checked(m_isotopeView->mode());
});
vLayout->addWidget(m_isotopeView);
vLayout->addWidget(m_radioButton);
setLayout(vLayout);
installEventFilter(this);
m_isotopeView->installEventFilter(this);
m_isotopeView->viewport()->installEventFilter(this);
m_radioButton->installEventFilter(this);
setFocusProxy(m_radioButton);
}
bool IsotopeTableSettingsCard::eventFilter(QObject *object, QEvent *event) {
Q_UNUSED(object);
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::MouseButton::LeftButton) {
m_radioButton->setChecked(true);
return true;
}
}
return false;
}
/*
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef ISOTOPETABLESETTINGSCARD_H
#define ISOTOPETABLESETTINGSCARD_H
#include <QFrame>
#include <QRadioButton>
#include "isotopeview.h"
class IsotopeTableSettingsCard : public QFrame
{
Q_OBJECT
public:
explicit IsotopeTableSettingsCard(QWidget *parent = nullptr);
IsotopeTableSettingsCard(QWidget *parent, int mode);
QString text() const {
return m_radioButton->text();
}
int mode() const {
return m_isotopeView->mode();
}
bool isChecked() const {
return m_radioButton->isChecked();
}
private:
void initialize();
private:
IsotopeView *m_isotopeView;
QRadioButton *m_radioButton;