Merge branch 'master' into selection-list

This commit is contained in:
Matthias Koefferlein 2022-10-13 09:32:16 +02:00
commit bc06b688ca
6 changed files with 221 additions and 52 deletions

View File

@ -845,7 +845,8 @@ Layout::delete_cells (const std::set<cell_index_type> &cells_to_delete)
if (manager () && manager ()->transacting ()) {
// note the "take" method - this takes out the cell
manager ()->queue (this, new NewRemoveCellOp (*c, cell_name (*c), true /*remove*/, take_cell (*c)));
std::string cn (cell_name (*c));
manager ()->queue (this, new NewRemoveCellOp (*c, cn, true /*remove*/, take_cell (*c)));
} else {
@ -913,7 +914,8 @@ Layout::delete_cell (cell_index_type id)
if (manager () && manager ()->transacting ()) {
// not the "take" method - this takes out the cell
manager ()->queue (this, new NewRemoveCellOp (id, cell_name (id), true /*remove*/, take_cell (id)));
std::string cn (cell_name (id));
manager ()->queue (this, new NewRemoveCellOp (id, cn, true /*remove*/, take_cell (id)));
} else {

View File

@ -11,6 +11,7 @@ HEADERS = \
layClipDialog.h \
layControlWidgetStack.h \
layCrashMessage.h \
layEnhancedTabWidget.h \
layFillDialog.h \
layGSIHelpProvider.h \
layHelpAboutDialog.h \
@ -121,6 +122,7 @@ SOURCES = \
layClipDialog.cc \
layControlWidgetStack.cc \
layCrashMessage.cc \
layEnhancedTabWidget.cc \
layFillDialog.cc \
layGSIHelpProvider.cc \
layHelpAboutDialog.cc \

View File

@ -0,0 +1,102 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2022 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 "layEnhancedTabWidget.h"
#include <QAction>
#include <QActionGroup>
#include <QMenu>
#include <QString>
#include <QToolButton>
namespace lay
{
// ---------------------------------------------------------------------------------------------
// EnhancedTabWidget implementation
EnhancedTabWidget::EnhancedTabWidget (QWidget *parent)
: QTabWidget (parent)
{
mp_list_tool_button = new QToolButton (this);
mp_list_tool_button->setAutoRaise (true);
mp_list_tool_button->setIcon (QIcon (QString::fromUtf8 (":/find_16px.png")));
mp_list_tool_button->setIconSize (QSize (20, 20));
mp_list_tool_button->setMenu (new QMenu (this));
mp_list_tool_button->setPopupMode (QToolButton::InstantPopup);
mp_list_tool_button->setToolButtonStyle (Qt::ToolButtonIconOnly);
mp_list_tool_button->setToolTip ( tr ("List of all opened views"));
setCornerWidget (mp_list_tool_button, Qt::TopRightCorner);
connect (mp_list_tool_button->menu (), SIGNAL (aboutToShow()),
this, SLOT (list_tool_button_menu_about_to_show()));
mp_list_action_group = new QActionGroup (this);
mp_list_action_group->setExclusive (true);
connect (mp_list_action_group, SIGNAL (triggered(QAction *)),
this, SLOT (list_action_group_triggered(QAction *)));
}
EnhancedTabWidget::~EnhancedTabWidget () = default;
void EnhancedTabWidget::tabInserted (int index)
{
QTabWidget::tabInserted (index);
update_list_button_visibility ();
}
void EnhancedTabWidget::tabRemoved (int index)
{
QTabWidget::tabRemoved (index);
update_list_button_visibility ();
}
void EnhancedTabWidget::list_action_group_triggered (QAction *action)
{
setCurrentIndex (action->data ().toInt ());
}
void EnhancedTabWidget::list_tool_button_menu_about_to_show ()
{
mp_list_tool_button->menu ()->clear ();
if (count () > 1) {
for (int i = 0; i < count (); ++i) {
QAction *action = mp_list_tool_button->menu ()->addAction (tabText (i));
action->setCheckable (true);
action->setData (QVariant (i));
mp_list_action_group->addAction (action);
}
mp_list_action_group->actions ().at (currentIndex ())->setChecked (true);
}
}
void EnhancedTabWidget::update_list_button_visibility()
{
if (cornerWidget (Qt::TopRightCorner) != nullptr) {
cornerWidget (Qt::TopRightCorner)->setVisible (count () > 1);
}
}
}

View File

@ -0,0 +1,62 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2022 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_layEnhancedTabWidget
#define HDR_layEnhancedTabWidget
#include <QTabWidget>
class QActionGroup;
class QToolButton;
namespace lay
{
class EnhancedTabWidget
: public QTabWidget
{
Q_OBJECT
public:
EnhancedTabWidget (QWidget *parent);
~EnhancedTabWidget () override;
protected:
void tabInserted (int index) override;
void tabRemoved (int index) override;
private slots:
void list_action_group_triggered (QAction* action);
void list_tool_button_menu_about_to_show ();
private:
QActionGroup *mp_list_action_group;
QToolButton *mp_list_tool_button;
void update_list_button_visibility ();
};
}
#endif

View File

@ -70,6 +70,7 @@
#include "layDialogs.h"
#include "laybasicConfig.h"
#include "layConfig.h"
#include "layEnhancedTabWidget.h"
#include "layMainWindow.h"
#include "layHelpDialog.h"
#include "layNavigator.h"
@ -227,12 +228,12 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
vbl->setContentsMargins (0, 0, 0, 0);
vbl->setSpacing (0);
mp_tab_bar = new QTabBar (mp_main_frame);
vbl->addWidget (mp_tab_bar);
connect (mp_tab_bar, SIGNAL (currentChanged (int)), this, SLOT (view_selected (int)));
mp_tab_widget = new EnhancedTabWidget (mp_main_frame);
vbl->addWidget (mp_tab_widget);
connect (mp_tab_widget, SIGNAL (currentChanged (int)), this, SLOT (view_selected (int)));
#if QT_VERSION >= 0x040500
mp_tab_bar->setTabsClosable(true);
connect (mp_tab_bar, SIGNAL (tabCloseRequested (int)), this, SLOT (tab_close_requested (int)));
mp_tab_widget->setTabsClosable(true);
connect (mp_tab_widget, SIGNAL (tabCloseRequested (int)), this, SLOT (tab_close_requested (int)));
#endif
mp_hp_dock_widget = new QDockWidget (QObject::tr ("Cells"), this);
@ -682,8 +683,8 @@ MainWindow::close_all ()
// Clear the tab bar
bool f = m_disable_tab_selected;
m_disable_tab_selected = true;
while (mp_tab_bar->count () > 0) {
mp_tab_bar->removeTab (mp_tab_bar->count () - 1);
while (mp_tab_widget->count () > 0) {
mp_tab_widget->removeTab (mp_tab_widget->count () - 1);
}
m_disable_tab_selected = f;
@ -2314,7 +2315,7 @@ MainWindow::view_selected (int index)
// Hint: setting the focus to the tab bar avoids problem with dangling keyboard focus.
// Sometimes, the focus was set to the hierarchy level spin buttons which caught Copy&Paste
// events in effect.
mp_tab_bar->setFocus ();
mp_tab_widget->setFocus ();
if (! m_disable_tab_selected) {
select_view (index);
@ -2335,7 +2336,7 @@ MainWindow::select_view (int index)
tl_assert (index >= 0 && index < int (views ()));
mp_tab_bar->setCurrentIndex (index);
mp_tab_widget->setCurrentIndex (index);
bool box_set = (m_synchronized_views && current_view () != 0);
db::DBox box;
@ -2564,7 +2565,7 @@ MainWindow::clone_current_view ()
bool f = m_disable_tab_selected;
m_disable_tab_selected = true;
int index = mp_tab_bar->insertTab (-1, tl::to_qstring (view->title ()));
int index = mp_tab_widget->insertTab (-1, mp_views.back (), tl::to_qstring (view->title ()));
m_disable_tab_selected = f;
view_created_event (index);
@ -2805,7 +2806,7 @@ MainWindow::close_view (int index)
box = view (index)->viewport ().box ();
}
mp_tab_bar->removeTab (index);
mp_tab_widget->removeTab (index);
mp_view_stack->remove_widget (index);
mp_lp_stack->remove_widget (index);
mp_layer_toolbox_stack->remove_widget (index);
@ -3381,7 +3382,7 @@ MainWindow::create_view ()
bool f = m_disable_tab_selected;
m_disable_tab_selected = true;
int index = mp_tab_bar->insertTab (-1, tl::to_qstring (current_view ()->title ()));
int index = mp_tab_widget->insertTab (-1, mp_views.back (), tl::to_qstring (current_view ()->title ()));
m_disable_tab_selected = f;
view_created_event (index);
@ -3444,7 +3445,7 @@ MainWindow::create_or_load_layout (const std::string *filename, const db::LoadLa
bool f = m_disable_tab_selected;
m_disable_tab_selected = true;
int index = mp_tab_bar->insertTab (-1, QString ());
int index = mp_tab_widget->insertTab (-1, mp_views.back (), QString ());
update_tab_title (index);
m_disable_tab_selected = f;
view_created_event (index);
@ -3484,8 +3485,8 @@ MainWindow::update_tab_title (int i)
title += v->title ();
}
if (tl::to_string (mp_tab_bar->tabText (i)) != title) {
mp_tab_bar->setTabText (i, tl::to_qstring (title));
if (tl::to_string (mp_tab_widget->tabText (i)) != title) {
mp_tab_widget->setTabText (i, tl::to_qstring (title));
}
if (v) {
@ -3500,8 +3501,8 @@ MainWindow::update_tab_title (int i)
files += tl::to_string (tr ("(not saved)"));
}
}
if (tl::to_string (mp_tab_bar->tabToolTip (i)) != files) {
mp_tab_bar->setTabToolTip (i, tl::to_qstring (files));
if (tl::to_string (mp_tab_widget->tabToolTip (i)) != files) {
mp_tab_widget->setTabToolTip (i, tl::to_qstring (files));
}
}
}

View File

@ -51,7 +51,7 @@
#include "tlDeferredExecution.h"
#include "gsi.h"
class QTabBar;
class QTabWidget;
class QToolBar;
class QLabel;
class QAction;
@ -682,7 +682,7 @@ private:
TextProgressDelegate m_text_progress;
// Main menu
QTabBar *mp_tab_bar;
QTabWidget *mp_tab_widget;
QToolBar *mp_tool_bar;
QDockWidget *mp_navigator_dock_widget;
lay::Navigator *mp_navigator;