mirror of https://github.com/KLayout/klayout.git
WIP
This commit is contained in:
parent
c2aa597022
commit
e058c47c02
|
|
@ -26,6 +26,7 @@
|
||||||
#define HDR_edtEditorOptionsPages
|
#define HDR_edtEditorOptionsPages
|
||||||
|
|
||||||
#include "layEditorOptionsPage.h"
|
#include "layEditorOptionsPage.h"
|
||||||
|
#include "layEditorOptionsPageWidget.h"
|
||||||
|
|
||||||
#include <tlVariant.h>
|
#include <tlVariant.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
#define HDR_edtRecentConfigurationPage
|
#define HDR_edtRecentConfigurationPage
|
||||||
|
|
||||||
#include "edtCommon.h"
|
#include "edtCommon.h"
|
||||||
#include "layEditorOptionsPage.h"
|
#include "layEditorOptionsPageWidget.h"
|
||||||
#include "tlObject.h"
|
#include "tlObject.h"
|
||||||
#include "tlDeferredExecution.h"
|
#include "tlDeferredExecution.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,28 @@
|
||||||
#include "tlInternational.h"
|
#include "tlInternational.h"
|
||||||
#include "layEditorOptionsPage.h"
|
#include "layEditorOptionsPage.h"
|
||||||
#include "layLayoutViewBase.h"
|
#include "layLayoutViewBase.h"
|
||||||
|
#include "tlClassRegistry.h"
|
||||||
#include "tlExceptions.h"
|
#include "tlExceptions.h"
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
|
|
||||||
namespace lay
|
namespace lay
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// EditorOptionsFactoryBase implementation
|
||||||
|
|
||||||
|
lay::EditorOptionsPage *
|
||||||
|
EditorOptionsPageFactoryBase::create_page_by_name (const std::string &name, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||||
|
{
|
||||||
|
auto reg = tl::Registrar<lay::EditorOptionsPageFactoryBase>::get_instance ();
|
||||||
|
for (auto i = reg->begin (); i != reg->end (); ++i) {
|
||||||
|
if (i.current_name () == name) {
|
||||||
|
return i->create_page (view, dispatcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// EditorOptionsPageCollection implementation
|
// EditorOptionsPageCollection implementation
|
||||||
|
|
||||||
|
|
@ -136,119 +150,5 @@ EditorOptionsPage::activate (bool active)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
|
||||||
// EditorOptionsPage implementation
|
|
||||||
|
|
||||||
EditorOptionsPageWidget::EditorOptionsPageWidget (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
|
||||||
: QWidget (0), EditorOptionsPage (view, dispatcher)
|
|
||||||
{
|
|
||||||
init (view, dispatcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorOptionsPageWidget::EditorOptionsPageWidget ()
|
|
||||||
: QWidget (0), EditorOptionsPage ()
|
|
||||||
{
|
|
||||||
// .. nothing yet ..
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorOptionsPageWidget::~EditorOptionsPageWidget ()
|
|
||||||
{
|
|
||||||
set_owner (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EditorOptionsPageWidget::edited ()
|
|
||||||
{
|
|
||||||
apply (dispatcher ());
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool is_parent_widget (QWidget *w, QWidget *parent)
|
|
||||||
{
|
|
||||||
while (w && w != parent) {
|
|
||||||
w = dynamic_cast<QWidget *> (w->parent ());
|
|
||||||
}
|
|
||||||
return w == parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
EditorOptionsPageWidget::focusNextPrevChild (bool next)
|
|
||||||
{
|
|
||||||
bool res = QWidget::focusNextPrevChild (next);
|
|
||||||
|
|
||||||
// Stop making the focus leave the page - this way we can jump back to the
|
|
||||||
// view on "enter"
|
|
||||||
if (res && ! is_modal_page () && ! is_parent_widget (QApplication::focusWidget (), this) && focusWidget ()) {
|
|
||||||
focusWidget ()->setFocus ();
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EditorOptionsPageWidget::keyPressEvent (QKeyEvent *event)
|
|
||||||
{
|
|
||||||
BEGIN_PROTECTED
|
|
||||||
if (! is_modal_page () &&
|
|
||||||
event->modifiers () == Qt::NoModifier &&
|
|
||||||
(event->key () == Qt::Key_Return || event->key () == Qt::Key_Enter || event->key () == Qt::Key_Escape)) {
|
|
||||||
if (event->key () == Qt::Key_Escape) {
|
|
||||||
// The Escape key creates a call to cancel()
|
|
||||||
cancel ();
|
|
||||||
} else {
|
|
||||||
// The Return key on a non-modal page commits the values and gives back the focus
|
|
||||||
// to the view
|
|
||||||
commit (dispatcher ());
|
|
||||||
}
|
|
||||||
view ()->set_focus ();
|
|
||||||
event->accept ();
|
|
||||||
} else {
|
|
||||||
QWidget::keyPressEvent (event);
|
|
||||||
}
|
|
||||||
END_PROTECTED
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
EditorOptionsPageWidget::event (QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type () == QEvent::ShortcutOverride) {
|
|
||||||
QKeyEvent *ke = dynamic_cast<QKeyEvent *> (event);
|
|
||||||
if (ke->key () == Qt::Key_Escape ||
|
|
||||||
ke->key () == Qt::Key_Tab ||
|
|
||||||
ke->key () == Qt::Key_Enter ||
|
|
||||||
ke->key () == Qt::Key_Return ||
|
|
||||||
ke->key () == Qt::Key_Backtab) {
|
|
||||||
// accept the shortcut override event for some keys, so we can handle
|
|
||||||
// it in keyPressEvent
|
|
||||||
ke->accept ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QWidget::event (event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EditorOptionsPageWidget::set_focus ()
|
|
||||||
{
|
|
||||||
if (isVisible ()) {
|
|
||||||
setFocus (Qt::TabFocusReason);
|
|
||||||
QWidget::focusNextPrevChild (true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EditorOptionsPageWidget::set_visible (bool visible)
|
|
||||||
{
|
|
||||||
setVisible (visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
EditorOptionsPageWidget::is_visible () const
|
|
||||||
{
|
|
||||||
return isVisible ();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,6 @@
|
||||||
|
|
||||||
#include "tlObject.h"
|
#include "tlObject.h"
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
|
||||||
# include <QWidget>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace db
|
namespace db
|
||||||
{
|
{
|
||||||
struct LayerProperties;
|
struct LayerProperties;
|
||||||
|
|
@ -149,34 +145,48 @@ private:
|
||||||
void attach_events ();
|
void attach_events ();
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
|
||||||
/**
|
/**
|
||||||
* @brief The base class for a object properties page
|
* @brief A basic factory class for editor options pages
|
||||||
|
*
|
||||||
|
* We will use it later to provide a registration-based specialized factory
|
||||||
|
* for Qt-enabled option pages, which we should not link here.
|
||||||
*/
|
*/
|
||||||
class LAYBASIC_PUBLIC EditorOptionsPageWidget
|
class LAYBASIC_PUBLIC EditorOptionsPageFactoryBase
|
||||||
: public QWidget, public EditorOptionsPage
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EditorOptionsPageWidget (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
|
EditorOptionsPageFactoryBase () { }
|
||||||
EditorOptionsPageWidget ();
|
virtual ~EditorOptionsPageFactoryBase () { }
|
||||||
virtual ~EditorOptionsPageWidget ();
|
|
||||||
|
|
||||||
virtual void set_focus ();
|
virtual lay::EditorOptionsPage *create_page (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) = 0;
|
||||||
virtual bool is_visible () const;
|
|
||||||
virtual void set_visible (bool visible);
|
|
||||||
virtual EditorOptionsPageWidget *widget () { return this; }
|
|
||||||
|
|
||||||
protected slots:
|
static lay::EditorOptionsPage *create_page_by_name (const std::string &name, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
|
||||||
void edited ();
|
};
|
||||||
|
|
||||||
protected:
|
/**
|
||||||
virtual bool focusNextPrevChild (bool next);
|
* @brief A specialized editor options page factory class for a specific type
|
||||||
virtual void keyPressEvent (QKeyEvent *event);
|
*
|
||||||
virtual bool event (QEvent *event);
|
* Register the factory using:
|
||||||
|
*
|
||||||
|
* #include "tlClassRegistry.h"
|
||||||
|
* static tl::RegisteredClass<lay::EditorOptionsPageFactoryBase> s_factory (new lay::EditorOptionsPageFactory<MyClass> (), 0, "MyClass");
|
||||||
|
*
|
||||||
|
* Later you can create a page from "MyName" using
|
||||||
|
*
|
||||||
|
* page = EditorOptionsPageFactoryBase::create_page_by_name ("MyClass", view, dispatcher);
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
class LAYBASIC_PUBLIC_TEMPLATE EditorOptionsPageFactory
|
||||||
|
: public EditorOptionsPageFactoryBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditorOptionsPageFactory () { }
|
||||||
|
virtual ~EditorOptionsPageFactory () { }
|
||||||
|
|
||||||
|
virtual lay::EditorOptionsPage *create_page (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||||
|
{
|
||||||
|
return new T (view, dispatcher);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif // defined(HAVE_QT)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@
|
||||||
namespace lay
|
namespace lay
|
||||||
{
|
{
|
||||||
|
|
||||||
const std::string move_editor_options_name ("move-editor-options");
|
LAYBASIC_PUBLIC std::string move_editor_options_name ("move-editor-options");
|
||||||
const std::string move_function_name ("move-execute");
|
LAYBASIC_PUBLIC std::string move_function_name ("move-execute");
|
||||||
const std::string move_distance_setter_name ("move-distance");
|
LAYBASIC_PUBLIC std::string move_distance_setter_name ("move-distance");
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// MoveService implementation
|
// MoveService implementation
|
||||||
|
|
@ -451,90 +451,6 @@ MoveService::finish ()
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class MoveToolboxPage
|
|
||||||
: public lay::EditorOptionsPageWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MoveToolboxPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
|
||||||
: lay::EditorOptionsPageWidget (view, dispatcher)
|
|
||||||
{
|
|
||||||
mp_layout = new QHBoxLayout (this);
|
|
||||||
|
|
||||||
mp_x_le = new QLineEdit (this);
|
|
||||||
mp_layout->addWidget (mp_x_le);
|
|
||||||
mp_y_le = new QLineEdit (this);
|
|
||||||
mp_layout->addWidget (mp_y_le);
|
|
||||||
mp_layout->addStretch (1);
|
|
||||||
|
|
||||||
hide ();
|
|
||||||
|
|
||||||
set_focus_page (true);
|
|
||||||
set_toolbox_widget (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string title () const
|
|
||||||
{
|
|
||||||
return "Move Options";
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char *name () const
|
|
||||||
{
|
|
||||||
return move_editor_options_name.c_str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int order () const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void deactivated ()
|
|
||||||
{
|
|
||||||
hide ();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void commit (lay::Dispatcher *dispatcher)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
|
|
||||||
double dx = 0.0, dy = 0.0;
|
|
||||||
|
|
||||||
tl::from_string (tl::to_string (mp_x_le->text ()), dx);
|
|
||||||
tl::from_string (tl::to_string (mp_y_le->text ()), dy);
|
|
||||||
|
|
||||||
dispatcher->call_function (move_function_name, db::DVector (dx, dy).to_string ());
|
|
||||||
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void configure (const std::string &name, const std::string &value)
|
|
||||||
{
|
|
||||||
if (name == move_distance_setter_name && ! mp_x_le->hasFocus () && ! mp_y_le->hasFocus ()) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
db::DVector mv;
|
|
||||||
tl::from_string (value, mv);
|
|
||||||
|
|
||||||
mp_x_le->setText (tl::to_qstring (tl::micron_to_string (mv.x ())));
|
|
||||||
mp_y_le->setText (tl::to_qstring (tl::micron_to_string (mv.y ())));
|
|
||||||
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QHBoxLayout *mp_layout;
|
|
||||||
QLineEdit *mp_x_le, *mp_y_le;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class MoveServiceDeclaration
|
class MoveServiceDeclaration
|
||||||
: public lay::PluginDeclaration
|
: public lay::PluginDeclaration
|
||||||
{
|
{
|
||||||
|
|
@ -550,13 +466,13 @@ public:
|
||||||
return new MoveService (view);
|
return new MoveService (view);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_QT)
|
|
||||||
virtual void get_editor_options_pages (std::vector<lay::EditorOptionsPage *> &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) const
|
virtual void get_editor_options_pages (std::vector<lay::EditorOptionsPage *> &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) const
|
||||||
{
|
{
|
||||||
pages.push_back (new MoveToolboxPage (view, dispatcher));
|
lay::EditorOptionsPage *page = lay::EditorOptionsPageFactoryBase::create_page_by_name (move_editor_options_name, view, dispatcher);
|
||||||
pages.back ()->set_plugin_declaration (this);
|
if (page) {
|
||||||
|
pages.push_back (page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static tl::RegisteredClass<lay::PluginDeclaration> move_service_decl (new MoveServiceDeclaration (), -970, "laybasic::MoveServicePlugin");
|
static tl::RegisteredClass<lay::PluginDeclaration> move_service_decl (new MoveServiceDeclaration (), -970, "laybasic::MoveServicePlugin");
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@
|
||||||
|
|
||||||
namespace lay {
|
namespace lay {
|
||||||
|
|
||||||
|
LAYBASIC_PUBLIC extern std::string move_editor_options_name;
|
||||||
|
LAYBASIC_PUBLIC extern std::string move_function_name;
|
||||||
|
LAYBASIC_PUBLIC extern std::string move_distance_setter_name;
|
||||||
|
|
||||||
class LayoutViewBase;
|
class LayoutViewBase;
|
||||||
|
|
||||||
class LAYBASIC_PUBLIC MoveService :
|
class LAYBASIC_PUBLIC MoveService :
|
||||||
|
|
|
||||||
|
|
@ -1473,6 +1473,9 @@ DecoratedLineEdit::DecoratedLineEdit (QWidget *parent)
|
||||||
mp_clear_label->setCursor (Qt::ArrowCursor);
|
mp_clear_label->setCursor (Qt::ArrowCursor);
|
||||||
mp_clear_label->setPixmap (QString::fromUtf8 (":/clear_edit_16px@2x.png"));
|
mp_clear_label->setPixmap (QString::fromUtf8 (":/clear_edit_16px@2x.png"));
|
||||||
|
|
||||||
|
mp_front_label = new QLabel (this);
|
||||||
|
mp_front_label->hide ();
|
||||||
|
|
||||||
QMargins margins = textMargins ();
|
QMargins margins = textMargins ();
|
||||||
m_default_left_margin = margins.left ();
|
m_default_left_margin = margins.left ();
|
||||||
m_default_right_margin = margins.right ();
|
m_default_right_margin = margins.right ();
|
||||||
|
|
@ -1535,43 +1538,57 @@ bool DecoratedLineEdit::focusNextPrevChild (bool next)
|
||||||
return QLineEdit::focusNextPrevChild (next);
|
return QLineEdit::focusNextPrevChild (next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecoratedLineEdit::set_margins ()
|
||||||
|
{
|
||||||
|
int right_margin = m_default_right_margin;
|
||||||
|
int left_margin = m_default_left_margin;
|
||||||
|
|
||||||
|
// right parts
|
||||||
|
if (m_clear_button_enabled) {
|
||||||
|
right_margin += mp_clear_label->sizeHint ().width () + le_decoration_space;
|
||||||
|
}
|
||||||
|
|
||||||
|
// left parts
|
||||||
|
if (! m_label.empty ()) {
|
||||||
|
left_margin += mp_front_label->sizeHint ().width () + le_decoration_space;
|
||||||
|
}
|
||||||
|
if (m_options_button_enabled) {
|
||||||
|
left_margin += mp_options_label->sizeHint ().width () + le_decoration_space;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMargins margins = textMargins ();
|
||||||
|
margins.setRight (right_margin);
|
||||||
|
margins.setLeft (left_margin);
|
||||||
|
setTextMargins (margins);
|
||||||
|
|
||||||
|
resizeEvent (0);
|
||||||
|
}
|
||||||
|
|
||||||
void DecoratedLineEdit::set_clear_button_enabled (bool en)
|
void DecoratedLineEdit::set_clear_button_enabled (bool en)
|
||||||
{
|
{
|
||||||
if (en != m_clear_button_enabled) {
|
if (en != m_clear_button_enabled) {
|
||||||
|
|
||||||
m_clear_button_enabled = en;
|
m_clear_button_enabled = en;
|
||||||
mp_clear_label->setVisible (en);
|
mp_clear_label->setVisible (en);
|
||||||
|
set_margins ();
|
||||||
QMargins margins = textMargins ();
|
|
||||||
if (! en) {
|
|
||||||
margins.setRight (m_default_right_margin);
|
|
||||||
} else {
|
|
||||||
margins.setRight (m_default_right_margin + mp_clear_label->sizeHint ().width () + le_decoration_space);
|
|
||||||
}
|
|
||||||
setTextMargins (margins);
|
|
||||||
|
|
||||||
resizeEvent (0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecoratedLineEdit::set_options_button_enabled (bool en)
|
void DecoratedLineEdit::set_options_button_enabled (bool en)
|
||||||
{
|
{
|
||||||
if (en != m_options_button_enabled) {
|
if (en != m_options_button_enabled) {
|
||||||
|
|
||||||
m_options_button_enabled = en;
|
m_options_button_enabled = en;
|
||||||
mp_options_label->setVisible (en);
|
mp_options_label->setVisible (en);
|
||||||
|
set_margins ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QMargins margins = textMargins ();
|
void DecoratedLineEdit::set_label (const std::string &label)
|
||||||
if (! en) {
|
{
|
||||||
margins.setLeft (m_default_left_margin);
|
if (label != m_label) {
|
||||||
} else {
|
m_label = label;
|
||||||
margins.setLeft (m_default_left_margin + mp_options_label->sizeHint ().width () + le_decoration_space);
|
mp_front_label->setVisible (! label.empty ());
|
||||||
}
|
mp_front_label->setText (tl::to_qstring (label));
|
||||||
setTextMargins (margins);
|
set_margins ();
|
||||||
|
|
||||||
resizeEvent (0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1621,17 +1638,27 @@ void DecoratedLineEdit::mousePressEvent (QMouseEvent *event)
|
||||||
void DecoratedLineEdit::resizeEvent (QResizeEvent *event)
|
void DecoratedLineEdit::resizeEvent (QResizeEvent *event)
|
||||||
{
|
{
|
||||||
int fw = hasFrame () ? le_frame_width : 0;
|
int fw = hasFrame () ? le_frame_width : 0;
|
||||||
|
QRect r = geometry ();
|
||||||
|
|
||||||
if (m_clear_button_enabled) {
|
int left = fw, right = r.width () - fw;
|
||||||
QSize label_size = mp_clear_label->sizeHint ();
|
|
||||||
QRect r = geometry ();
|
|
||||||
mp_clear_label->setGeometry (r.width () - fw - label_size.width (), 0, label_size.width (), r.height ());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_options_button_enabled) {
|
if (m_options_button_enabled) {
|
||||||
QSize label_size = mp_options_label->sizeHint ();
|
QSize label_size = mp_options_label->sizeHint ();
|
||||||
QRect r = geometry ();
|
mp_options_label->setGeometry (left, 0, label_size.width (), r.height ());
|
||||||
mp_options_label->setGeometry (fw, 0, label_size.width (), r.height ());
|
left += label_size.width () + le_decoration_space;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! m_label.empty ()) {
|
||||||
|
QSize label_size = mp_front_label->sizeHint ();
|
||||||
|
mp_front_label->setGeometry (left, 0, label_size.width (), r.height ());
|
||||||
|
left += label_size.width () + le_decoration_space;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_clear_button_enabled) {
|
||||||
|
QSize label_size = mp_clear_label->sizeHint ();
|
||||||
|
right -= label_size.width ();
|
||||||
|
mp_clear_label->setGeometry (right, 0, label_size.width (), r.height ());
|
||||||
|
right -= le_decoration_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit::resizeEvent (event);
|
QLineEdit::resizeEvent (event);
|
||||||
|
|
|
||||||
|
|
@ -566,6 +566,19 @@ public:
|
||||||
return m_tab_signal_enabled;
|
return m_tab_signal_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a label in front of the line edit
|
||||||
|
*/
|
||||||
|
void set_label (const std::string &label);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the label
|
||||||
|
*/
|
||||||
|
const std::string &label () const
|
||||||
|
{
|
||||||
|
return m_label;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void options_button_clicked ();
|
void options_button_clicked ();
|
||||||
void esc_pressed ();
|
void esc_pressed ();
|
||||||
|
|
@ -588,8 +601,12 @@ private:
|
||||||
bool m_tab_signal_enabled;
|
bool m_tab_signal_enabled;
|
||||||
QLabel *mp_options_label;
|
QLabel *mp_options_label;
|
||||||
QLabel *mp_clear_label;
|
QLabel *mp_clear_label;
|
||||||
|
QLabel *mp_front_label;
|
||||||
QMenu *mp_options_menu;
|
QMenu *mp_options_menu;
|
||||||
int m_default_left_margin, m_default_right_margin;
|
int m_default_left_margin, m_default_right_margin;
|
||||||
|
std::string m_label;
|
||||||
|
|
||||||
|
void set_margins ();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
KLayout Layout Viewer
|
||||||
|
Copyright (C) 2006-2025 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 "layEditorOptionsPageWidget.h"
|
||||||
|
#include "layLayoutViewBase.h"
|
||||||
|
#include "tlExceptions.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
|
namespace lay
|
||||||
|
{
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// EditorOptionsPageWidget implementation
|
||||||
|
|
||||||
|
EditorOptionsPageWidget::EditorOptionsPageWidget (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||||
|
: QWidget (0), EditorOptionsPage (view, dispatcher), m_is_transparent (false)
|
||||||
|
{
|
||||||
|
init (view, dispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorOptionsPageWidget::EditorOptionsPageWidget ()
|
||||||
|
: QWidget (0), EditorOptionsPage ()
|
||||||
|
{
|
||||||
|
// .. nothing yet ..
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorOptionsPageWidget::~EditorOptionsPageWidget ()
|
||||||
|
{
|
||||||
|
set_owner (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::edited ()
|
||||||
|
{
|
||||||
|
apply (dispatcher ());
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_parent_widget (QWidget *w, QWidget *parent)
|
||||||
|
{
|
||||||
|
while (w && w != parent) {
|
||||||
|
w = dynamic_cast<QWidget *> (w->parent ());
|
||||||
|
}
|
||||||
|
return w == parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
EditorOptionsPageWidget::focusNextPrevChild (bool next)
|
||||||
|
{
|
||||||
|
bool res = QWidget::focusNextPrevChild (next);
|
||||||
|
|
||||||
|
// Stop making the focus leave the page - this way we can jump back to the
|
||||||
|
// view on "enter"
|
||||||
|
if (res && ! is_modal_page () && ! is_parent_widget (QApplication::focusWidget (), this) && focusWidget ()) {
|
||||||
|
focusWidget ()->setFocus ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::keyPressEvent (QKeyEvent *event)
|
||||||
|
{
|
||||||
|
BEGIN_PROTECTED
|
||||||
|
if (! is_modal_page () &&
|
||||||
|
event->modifiers () == Qt::NoModifier &&
|
||||||
|
(event->key () == Qt::Key_Return || event->key () == Qt::Key_Enter || event->key () == Qt::Key_Escape)) {
|
||||||
|
if (event->key () == Qt::Key_Escape) {
|
||||||
|
// The Escape key creates a call to cancel()
|
||||||
|
cancel ();
|
||||||
|
} else {
|
||||||
|
// The Return key on a non-modal page commits the values and gives back the focus
|
||||||
|
// to the view
|
||||||
|
commit (dispatcher ());
|
||||||
|
}
|
||||||
|
view ()->set_focus ();
|
||||||
|
event->accept ();
|
||||||
|
} else {
|
||||||
|
QWidget::keyPressEvent (event);
|
||||||
|
}
|
||||||
|
END_PROTECTED
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
EditorOptionsPageWidget::event (QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type () == QEvent::ShortcutOverride) {
|
||||||
|
QKeyEvent *ke = dynamic_cast<QKeyEvent *> (event);
|
||||||
|
if (ke->key () == Qt::Key_Escape ||
|
||||||
|
ke->key () == Qt::Key_Tab ||
|
||||||
|
ke->key () == Qt::Key_Enter ||
|
||||||
|
ke->key () == Qt::Key_Return ||
|
||||||
|
ke->key () == Qt::Key_Backtab) {
|
||||||
|
// accept the shortcut override event for some keys, so we can handle
|
||||||
|
// it in keyPressEvent
|
||||||
|
ke->accept ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QWidget::event (event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::resizeEvent (QResizeEvent *e)
|
||||||
|
{
|
||||||
|
// makes the widget transparent
|
||||||
|
// see https://stackoverflow.com/questions/27855137/how-to-disable-the-delivery-of-mouse-events-to-the-widget-but-not-its-children-i
|
||||||
|
if (e) {
|
||||||
|
QWidget::resizeEvent (e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_is_transparent) {
|
||||||
|
QRegion reg (frameGeometry ());
|
||||||
|
reg -= QRegion (geometry ());
|
||||||
|
reg += childrenRegion ();
|
||||||
|
setMask (reg);
|
||||||
|
} else {
|
||||||
|
clearMask ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::set_transparent (bool f)
|
||||||
|
{
|
||||||
|
if (f != m_is_transparent) {
|
||||||
|
m_is_transparent = f;
|
||||||
|
resizeEvent (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::set_focus ()
|
||||||
|
{
|
||||||
|
if (isVisible ()) {
|
||||||
|
setFocus (Qt::TabFocusReason);
|
||||||
|
QWidget::focusNextPrevChild (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EditorOptionsPageWidget::set_visible (bool visible)
|
||||||
|
{
|
||||||
|
setVisible (visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
EditorOptionsPageWidget::is_visible () const
|
||||||
|
{
|
||||||
|
return isVisible ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
KLayout Layout Viewer
|
||||||
|
Copyright (C) 2006-2025 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_layEditorOptionsPageWidget
|
||||||
|
#define HDR_layEditorOptionsPageWidget
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "layviewCommon.h"
|
||||||
|
#include "layEditorOptionsPage.h"
|
||||||
|
|
||||||
|
namespace lay
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The base class for a object properties page
|
||||||
|
*/
|
||||||
|
class LAYVIEW_PUBLIC EditorOptionsPageWidget
|
||||||
|
: public QWidget, public EditorOptionsPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
EditorOptionsPageWidget (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
|
||||||
|
EditorOptionsPageWidget ();
|
||||||
|
virtual ~EditorOptionsPageWidget ();
|
||||||
|
|
||||||
|
virtual void set_focus ();
|
||||||
|
virtual bool is_visible () const;
|
||||||
|
virtual void set_visible (bool visible);
|
||||||
|
virtual EditorOptionsPageWidget *widget () { return this; }
|
||||||
|
|
||||||
|
void set_transparent (bool f);
|
||||||
|
bool is_transparent () const { return m_is_transparent; }
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void edited ();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool focusNextPrevChild (bool next);
|
||||||
|
virtual void keyPressEvent (QKeyEvent *event);
|
||||||
|
virtual void resizeEvent (QResizeEvent *e);
|
||||||
|
virtual bool event (QEvent *event);
|
||||||
|
|
||||||
|
bool m_is_transparent;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "tlInternational.h"
|
#include "tlInternational.h"
|
||||||
#include "layEditorOptionsPages.h"
|
#include "layEditorOptionsPages.h"
|
||||||
|
#include "layEditorOptionsPageWidget.h"
|
||||||
#include "tlExceptions.h"
|
#include "tlExceptions.h"
|
||||||
#include "layPlugin.h"
|
#include "layPlugin.h"
|
||||||
#include "layLayoutViewBase.h"
|
#include "layLayoutViewBase.h"
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@
|
||||||
#include "layBookmarksView.h"
|
#include "layBookmarksView.h"
|
||||||
#include "layEditorOptionsFrame.h"
|
#include "layEditorOptionsFrame.h"
|
||||||
#include "layEditorOptionsPages.h"
|
#include "layEditorOptionsPages.h"
|
||||||
|
#include "layEditorOptionsPageWidget.h"
|
||||||
#include "layUtils.h"
|
#include "layUtils.h"
|
||||||
#include "layPropertiesDialog.h"
|
#include "layPropertiesDialog.h"
|
||||||
#include "layQtTools.h"
|
#include "layQtTools.h"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
KLayout Layout Viewer
|
||||||
|
Copyright (C) 2006-2025 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 "layMoveEditorOptionsPage.h"
|
||||||
|
#include "layWidgets.h"
|
||||||
|
#include "layDispatcher.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
namespace lay
|
||||||
|
{
|
||||||
|
|
||||||
|
MoveEditorOptionsPage::MoveEditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||||
|
: lay::EditorOptionsPageWidget (view, dispatcher)
|
||||||
|
{
|
||||||
|
mp_layout = new QHBoxLayout (this);
|
||||||
|
|
||||||
|
mp_x_le = new lay::DecoratedLineEdit (this);
|
||||||
|
mp_x_le->set_label ("dx:");
|
||||||
|
mp_layout->addWidget (mp_x_le);
|
||||||
|
|
||||||
|
mp_y_le = new lay::DecoratedLineEdit (this);
|
||||||
|
mp_y_le->set_label ("dy:");
|
||||||
|
mp_layout->addWidget (mp_y_le);
|
||||||
|
|
||||||
|
mp_layout->addStretch (1);
|
||||||
|
|
||||||
|
hide ();
|
||||||
|
|
||||||
|
set_focus_page (true);
|
||||||
|
set_toolbox_widget (true);
|
||||||
|
set_transparent (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
MoveEditorOptionsPage::title () const
|
||||||
|
{
|
||||||
|
return "Move Options";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
MoveEditorOptionsPage::name () const
|
||||||
|
{
|
||||||
|
return move_editor_options_name.c_str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
MoveEditorOptionsPage::order () const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MoveEditorOptionsPage::deactivated ()
|
||||||
|
{
|
||||||
|
hide ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MoveEditorOptionsPage::commit (lay::Dispatcher *dispatcher)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
double dx = 0.0, dy = 0.0;
|
||||||
|
|
||||||
|
tl::from_string (tl::to_string (mp_x_le->text ()), dx);
|
||||||
|
tl::from_string (tl::to_string (mp_y_le->text ()), dy);
|
||||||
|
|
||||||
|
dispatcher->call_function (move_function_name, db::DVector (dx, dy).to_string ());
|
||||||
|
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MoveEditorOptionsPage::configure (const std::string &name, const std::string &value)
|
||||||
|
{
|
||||||
|
if (name == move_distance_setter_name && ! mp_x_le->hasFocus () && ! mp_y_le->hasFocus ()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
db::DVector mv;
|
||||||
|
tl::from_string (value, mv);
|
||||||
|
|
||||||
|
mp_x_le->setText (tl::to_qstring (tl::micron_to_string (mv.x ())));
|
||||||
|
mp_y_le->setText (tl::to_qstring (tl::micron_to_string (mv.y ())));
|
||||||
|
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// registers the factory for the move plugin
|
||||||
|
static tl::RegisteredClass<lay::EditorOptionsPageFactoryBase> s_factory (new lay::EditorOptionsPageFactory<MoveEditorOptionsPage> (), 0, move_editor_options_name.c_str ());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
KLayout Layout Viewer
|
||||||
|
Copyright (C) 2006-2025 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_layMoveEditorOptionsPage
|
||||||
|
#define HDR_layMoveEditorOptionsPage
|
||||||
|
|
||||||
|
#include "layviewCommon.h"
|
||||||
|
#include "layEditorOptionsPageWidget.h"
|
||||||
|
#include "layMove.h"
|
||||||
|
|
||||||
|
class QHBoxLayout;
|
||||||
|
|
||||||
|
namespace lay {
|
||||||
|
class DecoratedLineEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace lay {
|
||||||
|
|
||||||
|
class MoveEditorOptionsPage
|
||||||
|
: public lay::EditorOptionsPageWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MoveEditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
|
||||||
|
|
||||||
|
virtual std::string title () const;
|
||||||
|
virtual const char *name () const;
|
||||||
|
virtual int order () const;
|
||||||
|
virtual void deactivated ();
|
||||||
|
virtual void commit (lay::Dispatcher *dispatcher);
|
||||||
|
virtual void configure (const std::string &name, const std::string &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout *mp_layout;
|
||||||
|
lay::DecoratedLineEdit *mp_x_le, *mp_y_le;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -9,17 +9,21 @@ DEFINES += MAKE_LAYVIEW_LIBRARY
|
||||||
RESOURCES = \
|
RESOURCES = \
|
||||||
|
|
||||||
SOURCES = \
|
SOURCES = \
|
||||||
|
layEditorOptionsPageWidget.cc \
|
||||||
layGridNet.cc \
|
layGridNet.cc \
|
||||||
layEditorOptionsFrame.cc \
|
layEditorOptionsFrame.cc \
|
||||||
layEditorOptionsPages.cc \
|
layEditorOptionsPages.cc \
|
||||||
|
layMoveEditorOptionsPage.cc \
|
||||||
layviewForceLink.cc \
|
layviewForceLink.cc \
|
||||||
gsiDeclLayAdditional.cc \
|
gsiDeclLayAdditional.cc \
|
||||||
|
|
||||||
HEADERS = \
|
HEADERS = \
|
||||||
|
layEditorOptionsPageWidget.h \
|
||||||
layGridNet.h \
|
layGridNet.h \
|
||||||
layEditorOptionsFrame.h \
|
layEditorOptionsFrame.h \
|
||||||
layEditorOptionsPages.h \
|
layEditorOptionsPages.h \
|
||||||
layLayoutView.h \
|
layLayoutView.h \
|
||||||
|
layMoveEditorOptionsPage.h \
|
||||||
layviewForceLink.h \
|
layviewForceLink.h \
|
||||||
|
|
||||||
!equals(HAVE_QT, "0") {
|
!equals(HAVE_QT, "0") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue