Adding a ruler options widget page

This commit is contained in:
Matthias Koefferlein 2026-05-24 00:16:35 +02:00
parent 98a8d370aa
commit c8362d16f1
4 changed files with 421 additions and 0 deletions

242
src/ant/ant/RulerOptions.ui Normal file
View File

@ -0,0 +1,242 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RulerOptions</class>
<widget class="QWidget" name="RulerOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>446</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>446</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Snapping</string>
</property>
<layout class="QGridLayout" name="_5">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="snap_to_grid_cbx">
<property name="text">
<string>Snap to grid</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="snap_to_objects_cbx">
<property name="text">
<string>Snap to edge/vertex</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Angle Constraints</string>
</property>
<layout class="QGridLayout" name="_2">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="0" column="1">
<widget class="QComboBox" name="angle_cb">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<item>
<property name="text">
<string>Any Angle</string>
</property>
</item>
<item>
<property name="text">
<string>Diagonal</string>
</property>
</item>
<item>
<property name="text">
<string>Diagonal only</string>
</property>
</item>
<item>
<property name="text">
<string>Orthogonal</string>
</property>
</item>
<item>
<property name="text">
<string>Horizontal only</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical only</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Ruler direction</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Note: certain rulers may ignore these options</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>121</width>
<height>70</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>snap_to_grid_cbx</tabstop>
<tabstop>snap_to_objects_cbx</tabstop>
<tabstop>angle_cb</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -14,6 +14,7 @@ FORMS = \
RulerConfigPage3.ui \
RulerConfigPage4.ui \
RulerPropertiesPage.ui \
RulerOptions.ui \
}
@ -22,10 +23,12 @@ FORMS = \
HEADERS = \
antConfigPage.h \
antPropertiesPage.h \
antRulerOptionsPage.h
SOURCES = \
antConfigPage.cc \
antPropertiesPage.cc \
antRulerOptionsPage.cc
# Enabled without Qt:

View File

@ -0,0 +1,114 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2026 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "antRulerOptionsPage.h"
#include "antConfig.h"
#include "laySnap.h"
#include "layConverters.h"
#include "layDispatcher.h"
#include "tlString.h"
#include "tlClassRegistry.h"
#include "ui_RulerOptions.h"
namespace ant
{
// ------------------------------------------------------------------
// RulerOptionsPage implementation
RulerOptionsPage::RulerOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
: lay::EditorOptionsPageWidget (view, dispatcher)
{
mp_ui = new Ui::RulerOptions ();
mp_ui->setupUi (this);
connect (mp_ui->angle_cb, SIGNAL (activated (int)), this, SLOT (edited ()));
connect (mp_ui->snap_to_grid_cbx, SIGNAL (clicked ()), this, SLOT (edited ()));
connect (mp_ui->snap_to_objects_cbx, SIGNAL (clicked ()), this, SLOT (edited ()));
}
RulerOptionsPage::~RulerOptionsPage ()
{
delete mp_ui;
mp_ui = 0;
}
std::string
RulerOptionsPage::title () const
{
return tl::to_string (QObject::tr ("Ruler Options"));
}
// Must match order in angle_cb
static std::vector<lay::angle_constraint_type> s_ac_options =
{
lay::AC_Any,
lay::AC_Diagonal,
lay::AC_DiagonalOnly,
lay::AC_Ortho,
lay::AC_Horizontal,
lay::AC_Vertical
};
void
RulerOptionsPage::apply (lay::Dispatcher *root)
{
lay::angle_constraint_type ac = lay::AC_Any;
int ai = mp_ui->angle_cb->currentIndex ();
if (ai >= 0 && ai < int (s_ac_options.size ())) {
ac = s_ac_options [ai];
}
lay::ACConverter acc;
root->config_set (cfg_ruler_snap_mode, acc.to_string (ac));
root->config_set (cfg_ruler_obj_snap, tl::to_string (mp_ui->snap_to_objects_cbx->isChecked ()));
root->config_set (cfg_ruler_grid_snap, tl::to_string (mp_ui->snap_to_grid_cbx->isChecked ()));
}
void
RulerOptionsPage::setup (lay::Dispatcher *root)
{
lay::ACConverter acc;
lay::angle_constraint_type ac;
ac = lay::AC_Any;
root->config_get (cfg_ruler_snap_mode, ac, acc);
for (int ai = 0; ai < int (s_ac_options.size ()); ++ai) {
if (s_ac_options [ai] == ac) {
mp_ui->angle_cb->setCurrentIndex (ai);
}
}
bool snap_to_grid = false;
root->config_get (cfg_ruler_grid_snap, snap_to_grid);
mp_ui->snap_to_grid_cbx->setChecked (snap_to_grid);
bool snap_to_objects = false;
root->config_get (cfg_ruler_obj_snap, snap_to_objects);
mp_ui->snap_to_objects_cbx->setChecked (snap_to_objects);
}
static tl::RegisteredClass<lay::EditorOptionsPageFactoryBase> s_factory_ruler_options (new lay::EditorOptionsPageFactory<RulerOptionsPage> ("ant::RulerOptions"), 0);
}

View File

@ -0,0 +1,62 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2026 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_antRulerOptionsPage
#define HDR_antRulerOptionsPage
#include "antCommon.h"
#include "layEditorOptionsPageWidget.h"
namespace Ui
{
class RulerOptions;
}
namespace ant
{
/**
* @brief The generic properties page
*/
class RulerOptionsPage
: public lay::EditorOptionsPageWidget
{
Q_OBJECT
public:
RulerOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
~RulerOptionsPage ();
virtual std::string title () const;
virtual int order () const { return -10; }
void apply (lay::Dispatcher *root);
void setup (lay::Dispatcher *root);
private:
Ui::RulerOptions *mp_ui;
};
}
#endif