"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Plugins/Qt/qt_tm_widget.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

qt_tm_widget.cpp  (TeXmacs-1.99.4-src):qt_tm_widget.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 45 skipping to change at line 45
#include "QTMWindow.hpp" #include "QTMWindow.hpp"
#include "QTMStyle.hpp" // qtstyle() #include "QTMStyle.hpp" // qtstyle()
#include "QTMGuiHelper.hpp" // needed to connect() #include "QTMGuiHelper.hpp" // needed to connect()
#include "QTMInteractivePrompt.hpp" #include "QTMInteractivePrompt.hpp"
#include "QTMInteractiveInputHelper.hpp" #include "QTMInteractiveInputHelper.hpp"
int menu_count = 0; // zero if no menu is currently being displayed int menu_count = 0; // zero if no menu is currently being displayed
list<qt_tm_widget_rep*> waiting_widgets; list<qt_tm_widget_rep*> waiting_widgets;
static void static void
replaceActions (QWidget* dest, QWidget* src) { replaceActions (QWidget* dest, QList<QAction*>* src) {
//NOTE: the parent hierarchy of the actions is not modified while installing //NOTE: the parent hierarchy of the actions is not modified while installing
// the menu in the GUI (see qt_menu.hpp for this memory management // the menu in the GUI (see qt_menu.hpp for this memory management
// policy) // policy)
if (src == NULL || dest == NULL) if (src == NULL || dest == NULL)
FAILED ("replaceActions expects valid objects"); FAILED ("replaceActions expects valid objects");
dest->setUpdatesEnabled (false); dest->setUpdatesEnabled (false);
QList<QAction *> list = dest->actions(); QList<QAction *> list = dest->actions();
while (!list.isEmpty()) dest->removeAction (list.takeFirst()); for (int i = 0; i < list.count(); i++) {
list = src->actions(); QAction* a = list[i];
while (!list.isEmpty()) dest->addAction (list.takeFirst()); dest->removeAction (a);
}
for (int i = 0; i < src->count(); i++) {
QAction* a = (*src)[i];
dest->addAction(a);
}
dest->setUpdatesEnabled (true); dest->setUpdatesEnabled (true);
} }
static void static void
replaceButtons (QToolBar* dest, QWidget* src) { replaceButtons (QToolBar* dest, QList<QAction*>* src) {
if (src == NULL || dest == NULL) if (src == NULL || dest == NULL)
FAILED ("replaceButtons expects valid objects"); FAILED ("replaceButtons expects valid objects");
dest->setUpdatesEnabled (false); dest->setUpdatesEnabled (false);
bool visible = dest->isVisible(); bool visible = dest->isVisible();
if (visible) dest->hide(); //TRICK: to avoid flicker of the dest widget if (visible) dest->hide(); //TRICK: to avoid flicker of the dest widget
replaceActions (dest, src); replaceActions (dest, src);
QList<QObject*> list = dest->children(); QList<QObject*> list = dest->children();
for (int i = 0; i < list.count(); ++i) { for (int i = 0; i < list.count(); ++i) {
QToolButton* button = qobject_cast<QToolButton*> (list[i]); QToolButton* button = qobject_cast<QToolButton*> (list[i]);
if (button) { if (button) {
button->setPopupMode (QToolButton::InstantPopup); button->setPopupMode (QToolButton::InstantPopup);
button->setStyle (qtmstyle()); button->setStyle (qtmstyle());
skipping to change at line 155 skipping to change at line 160
// http://www.archivum.info/qt-interest@trolltech.com/2007-05/01453/Re:-QStatu sBar-size.html // http://www.archivum.info/qt-interest@trolltech.com/2007-05/01453/Re:-QStatu sBar-size.html
// The solution if due to Martin Petricek. He adds: // The solution if due to Martin Petricek. He adds:
// The docs says: If minimumSize() is set, the minimum size hint will be ig nored. // The docs says: If minimumSize() is set, the minimum size hint will be ig nored.
// Probably the minimum size hint was size of the lengthy message and // Probably the minimum size hint was size of the lengthy message and
// internal layout was enlarging the satusbar and the main window // internal layout was enlarging the satusbar and the main window
// Maybe the notice about QLayout that is at minimumSizeHint should be // Maybe the notice about QLayout that is at minimumSizeHint should be
// also at minimumSize, didn't notice it first time and spend lot of time // also at minimumSize, didn't notice it first time and spend lot of time
// trying to figure this out :) // trying to figure this out :)
bar->setMinimumWidth (2); bar->setMinimumWidth (2);
if (retina_scale > 1.0) {
int min_h= (int) floor (20 * retina_scale);
bar->setMinimumHeight (min_h);
}
mw->setStatusBar (bar); mw->setStatusBar (bar);
// toolbars // toolbars
mainToolBar = new QToolBar ("main toolbar", mw); mainToolBar = new QToolBar ("main toolbar", mw);
modeToolBar = new QToolBar ("mode toolbar", mw); modeToolBar = new QToolBar ("mode toolbar", mw);
focusToolBar = new QToolBar ("focus toolbar", mw); focusToolBar = new QToolBar ("focus toolbar", mw);
userToolBar = new QToolBar ("user toolbar", mw); userToolBar = new QToolBar ("user toolbar", mw);
bottomTools = new QDockWidget ("bottom tools", mw); bottomTools = new QDockWidget ("bottom tools", mw);
skipping to change at line 213 skipping to change at line 222
bl->setSpacing (0); bl->setSpacing (0);
cw->setLayout (bl); cw->setLayout (bl);
QWidget* q = main_widget->as_qwidget(); // force creation of QWidget QWidget* q = main_widget->as_qwidget(); // force creation of QWidget
q->setParent (qwid); // q->layout()->removeWidget(q) will reset the parent to this q->setParent (qwid); // q->layout()->removeWidget(q) will reset the parent to this
bl->addWidget (q); bl->addWidget (q);
mw->setCentralWidget (cw); mw->setCentralWidget (cw);
#ifdef UNIFIED_TOOLBAR #ifdef UNIFIED_TOOLBAR
mw->setUnifiedTitleAndToolBarOnMac(true); if (use_unified_toolbar) {
mw->setUnifiedTitleAndToolBarOnMac(true);
//WARNING: dumbToolBar is the toolbar installed on the top area of the //WARNING: dumbToolBar is the toolbar installed on the top area of the
//main widget which is then unified in the title bar. //main widget which is then unified in the title bar.
//to overcome some limitations of the unified toolbar implementation we //to overcome some limitations of the unified toolbar implementation we
//install the real toolbars as widgets in this toolbar. //install the real toolbars as widgets in this toolbar.
dumbToolBar = mw->addToolBar("dumb toolbar"); dumbToolBar = mw->addToolBar("dumb toolbar");
dumbToolBar->setMinimumHeight(30); dumbToolBar->setMinimumHeight(30);
//these are the actions related to the various toolbars to be installed in //these are the actions related to the various toolbars to be installed in
//the dumb toolbar. //the dumb toolbar.
mainToolBarAction = dumbToolBar->addWidget(mainToolBar); mainToolBarAction = dumbToolBar->addWidget(mainToolBar);
modeToolBarAction = NULL; modeToolBarAction = NULL;
// A ruler // A ruler
rulerWidget = new QWidget(cw); rulerWidget = new QWidget(cw);
rulerWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); rulerWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
rulerWidget->setMinimumHeight(1); rulerWidget->setMinimumHeight(1);
rulerWidget->setBackgroundRole(QPalette::Mid); rulerWidget->setBackgroundRole(QPalette::Mid);
// FIXME: how to use 112 (active) and 146 (passive) // FIXME: how to use 112 (active) and 146 (passive)
rulerWidget->setVisible(false); rulerWidget->setVisible(false);
rulerWidget->setAutoFillBackground(true); rulerWidget->setAutoFillBackground(true);
// rulerWidget = new QLabel("pippo", cw); // rulerWidget = new QLabel("pippo", cw);
// A second ruler (this one always visible) to separate from the canvas. // A second ruler (this one always visible) to separate from the canvas.
QWidget* r2 = new QWidget(mw); QWidget* r2 = new QWidget(mw);
r2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); r2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
r2->setMinimumHeight(1); r2->setMinimumHeight(1);
r2->setBackgroundRole(QPalette::Mid); r2->setBackgroundRole(QPalette::Mid);
r2->setVisible(true); r2->setVisible(true);
r2->setAutoFillBackground(true); r2->setAutoFillBackground(true);
bl->insertWidget(0, modeToolBar); bl->insertWidget(0, modeToolBar);
bl->insertWidget(1, rulerWidget); bl->insertWidget(1, rulerWidget);
bl->insertWidget(2, focusToolBar); bl->insertWidget(2, focusToolBar);
bl->insertWidget(3, userToolBar); bl->insertWidget(3, userToolBar);
bl->insertWidget(5, r2); bl->insertWidget(5, r2);
//mw->setContentsMargins (-2, -2, -2, -2); // Why this? //mw->setContentsMargins (-2, -2, -2, -2); // Why this?
bar->setContentsMargins (0, 1, 0, 1); bar->setContentsMargins (0, 1, 0, 1);
}
else {
mw->addToolBar (mainToolBar);
mw->addToolBarBreak ();
mw->addToolBar (modeToolBar);
mw->addToolBarBreak ();
mw->addToolBar (focusToolBar);
mw->addToolBarBreak ();
mw->addToolBar (userToolBar);
mw->addToolBarBreak ();
}
#else #else
mw->addToolBar (mainToolBar); mw->addToolBar (mainToolBar);
mw->addToolBarBreak (); mw->addToolBarBreak ();
mw->addToolBar (modeToolBar); mw->addToolBar (modeToolBar);
mw->addToolBarBreak (); mw->addToolBarBreak ();
mw->addToolBar (focusToolBar); mw->addToolBar (focusToolBar);
mw->addToolBarBreak (); mw->addToolBarBreak ();
mw->addToolBar (userToolBar); mw->addToolBar (userToolBar);
mw->addToolBarBreak (); mw->addToolBarBreak ();
skipping to change at line 324 skipping to change at line 345
if (sz.height () >= 24) { if (sz.height () >= 24) {
sz.setWidth (sz.width () + 2); sz.setWidth (sz.width () + 2);
sz.setHeight (sz.height () + 6); sz.setHeight (sz.height () + 6);
} }
else if (sz.height () >= 20) { else if (sz.height () >= 20) {
sz.setHeight (sz.height () + 2); sz.setHeight (sz.height () + 2);
} }
else if (sz.height () >= 16) { else if (sz.height () >= 16) {
sz.setHeight (sz.height () + 2); sz.setHeight (sz.height () + 2);
} }
//sz.setHeight ((int) floor (sz.height () * retina_scale + 0.5));
} }
/*! Return ourselves as a window widget. /*! Return ourselves as a window widget.
\param name A unique identifier for the window (e.g. "TeXmacs:3") \param name A unique identifier for the window (e.g. "TeXmacs:3")
*/ */
widget widget
qt_tm_widget_rep::plain_window_widget (string name, command _quit) { qt_tm_widget_rep::plain_window_widget (string name, command _quit) {
(void) _quit; // The widget already has a command. Don't overwrite. (void) _quit; // The widget already has a command. Don't overwrite.
orig_name = name; orig_name = name;
return this; return this;
skipping to change at line 383 skipping to change at line 405
bool new_menuVisibility = visibility[0]; bool new_menuVisibility = visibility[0];
if ( XOR(old_menuVisibility, new_menuVisibility) ) if ( XOR(old_menuVisibility, new_menuVisibility) )
mainwindow()->menuBar()->setVisible (new_menuVisibility); mainwindow()->menuBar()->setVisible (new_menuVisibility);
#endif #endif
//#if 0 //#if 0
#ifdef UNIFIED_TOOLBAR #ifdef UNIFIED_TOOLBAR
// do modifications only if needed to reduce flicker // do modifications only if needed to reduce flicker
if ( XOR(old_mainVisibility, new_mainVisibility) || if (use_unified_toolbar &&
XOR(old_modeVisibility, new_modeVisibility) ) (XOR(old_mainVisibility, new_mainVisibility) ||
XOR(old_modeVisibility, new_modeVisibility) ))
{ {
// ensure that the topmost visible toolbar is always unified on Mac // ensure that the topmost visible toolbar is always unified on Mac
// (actually only for main and mode toolbars, unifying focus is not // (actually only for main and mode toolbars, unifying focus is not
// appropriate) // appropriate)
QBoxLayout *bl = qobject_cast<QBoxLayout*>(mainwindow()->centralWidget()->la yout()); QBoxLayout *bl = qobject_cast<QBoxLayout*>(mainwindow()->centralWidget()->la yout());
if (modeToolBarAction) if (modeToolBarAction)
modeToolBarAction->setVisible(modeToolBar->isVisible()); modeToolBarAction->setVisible(modeToolBar->isVisible());
mainToolBarAction->setVisible(mainToolBar->isVisible()); mainToolBarAction->setVisible(mainToolBar->isVisible());
skipping to change at line 434 skipping to change at line 457
dumbToolBar->setVisible(false); dumbToolBar->setVisible(false);
dumbToolBar->removeAction(modeToolBarAction); dumbToolBar->removeAction(modeToolBarAction);
} }
} }
} }
#endif // UNIFIED_TOOLBAR #endif // UNIFIED_TOOLBAR
#undef XOR #undef XOR
{ {
QFont f = leftLabel->font(); QFont f = leftLabel->font();
int fs = as_int (get_preference ("gui:mini-fontsize", QTM_MINI_FONTSIZE)); int fs = as_int (get_preference ("gui:mini-fontsize", QTM_MINI_FONTSIZE));
f.setPointSize (fs > 0 ? fs : QTM_MINI_FONTSIZE); f.setPointSize (qt_zoom (fs > 0 ? fs : QTM_MINI_FONTSIZE));
leftLabel->setFont(f); leftLabel->setFont(f);
rightLabel->setFont(f); rightLabel->setFont(f);
} }
} }
widget widget
qt_tm_widget_rep::read(slot s, blackbox index) { qt_tm_widget_rep::read(slot s, blackbox index) {
widget ret; widget ret;
switch (s) { switch (s) {
skipping to change at line 706 skipping to change at line 729
check_type_id<bool> (type_id, s); check_type_id<bool> (type_id, s);
return close_box<bool> (prompt && prompt->isActive()); return close_box<bool> (prompt && prompt->isActive());
default: default:
return qt_window_widget_rep::query (s, type_id); return qt_window_widget_rep::query (s, type_id);
} }
} }
void void
qt_tm_widget_rep::install_main_menu () { qt_tm_widget_rep::install_main_menu () {
if (main_menu_widget == waiting_main_menu_widget) return;
main_menu_widget = waiting_main_menu_widget; main_menu_widget = waiting_main_menu_widget;
QMenu* src = main_menu_widget->get_qmenu(); QList<QAction*>* src = main_menu_widget->get_qactionlist();
if (!src) return; if (!src) return;
// REMARK: We do not want the menubar shared across windows as suggested
// in http://doc.qt.nokia.com/4.7/qmainwindow.html#menuBar
// e.g. :
//
// QMenuBar *dest = new QMenuBar(0);
// mainwindow()->setMenuBar(dest);
//
// as the default behavior on MacOS. The main reason is that in TeXmacs
// different windows can have different main menus so that it is indeed
// appropriate to change the main menu as the window focus changes.
// So we kindly ask to each window to give us its own menu and we install
// there our actions.
// So we do:
QMenuBar* dest = mainwindow()->menuBar(); QMenuBar* dest = mainwindow()->menuBar();
dest->clear();
// and everything is fine. for (int i = 0; i < src->count(); i++) {
QAction* a = (*src)[i];
// Also please note that we have to do the replacement and not simply
// install the menu returned by get_qmenu() since the main menu there
// could contain some default items appropriate for the given OS (like the
// service menu on MacOS) which are not present in our menu widget.
// UPDATE: But replaceActions() *does remove* all actions (!?)
// It looks more like the reason is that we have to "flatten out" the first
// level of the QMenu returned... ?
replaceActions (dest, src);
QList<QAction*> list = dest->actions();
for (int i = 0; i < list.count(); i++) {
QAction* a = list[i];
if (a->menu()) { if (a->menu()) {
//TRICK: Mac native QMenuBar accepts only menus which are already populate
d
// this will cause a problem for us, since menus are lazy and populated on
ly after triggering
// this is the reason we add a dummy action before inserting the menu
a->menu()->addAction("native menubar trick");
dest->addAction(a->menu()->menuAction());
QObject::connect (a->menu(), SIGNAL (aboutToShow()), QObject::connect (a->menu(), SIGNAL (aboutToShow()),
the_gui->gui_helper, SLOT (aboutToShowMainMenu())); the_gui->gui_helper, SLOT (aboutToShowMainMenu()));
QObject::connect (a->menu(), SIGNAL (aboutToHide()), QObject::connect (a->menu(), SIGNAL (aboutToHide()),
the_gui->gui_helper, SLOT (aboutToHideMainMenu())); the_gui->gui_helper, SLOT (aboutToHideMainMenu()));
} }
} }
} }
void void
qt_tm_widget_rep::write (slot s, blackbox index, widget w) { qt_tm_widget_rep::write (slot s, blackbox index, widget w) {
if (DEBUG_QT_WIDGETS) if (DEBUG_QT_WIDGETS)
debug_widgets << "qt_tm_widget_rep::write " << slot_name (s) << LF; debug_widgets << "qt_tm_widget_rep::write " << slot_name (s) << LF;
switch (s) { switch (s) {
// Widget w is usually a qt_simple_widget_rep, with a QTMWidget as // Widget w is usually a qt_simple_widget_rep, with a QTMWidget as
// underlying widget. We must discard the current main_widget and // underlying widget. We must discard the current main_widget and
skipping to change at line 801 skipping to change at line 802
else if (!contains (waiting_widgets, this)) else if (!contains (waiting_widgets, this))
// menu interaction ongoing, postpone new menu installation until done // menu interaction ongoing, postpone new menu installation until done
waiting_widgets << this; waiting_widgets << this;
} }
break; break;
case SLOT_MAIN_ICONS: case SLOT_MAIN_ICONS:
check_type_void (index, s); check_type_void (index, s);
{ {
main_icons_widget = concrete (w); main_icons_widget = concrete (w);
QMenu* m = main_icons_widget->get_qmenu(); QList<QAction*>* list = main_icons_widget->get_qactionlist();
if (m) { if (list) {
replaceButtons (mainToolBar, m); replaceButtons (mainToolBar, list);
update_visibility(); update_visibility();
} }
} }
break; break;
case SLOT_MODE_ICONS: case SLOT_MODE_ICONS:
check_type_void (index, s); check_type_void (index, s);
{ {
mode_icons_widget = concrete (w); mode_icons_widget = concrete (w);
QMenu* m = mode_icons_widget->get_qmenu(); QList<QAction*>* list = mode_icons_widget->get_qactionlist();
if (m) { if (list) {
replaceButtons (modeToolBar, m); replaceButtons (modeToolBar, list);
update_visibility(); update_visibility();
} }
} }
break; break;
case SLOT_FOCUS_ICONS: case SLOT_FOCUS_ICONS:
check_type_void (index, s); check_type_void (index, s);
{ {
focus_icons_widget = concrete (w); focus_icons_widget = concrete (w);
QMenu* m = focus_icons_widget->get_qmenu(); QList<QAction*>* list = focus_icons_widget->get_qactionlist();
if (m) { if (list) {
replaceButtons (focusToolBar, m); replaceButtons (focusToolBar, list);
update_visibility(); update_visibility();
} }
} }
break; break;
case SLOT_USER_ICONS: case SLOT_USER_ICONS:
check_type_void (index, s); check_type_void (index, s);
{ {
user_icons_widget = concrete (w); user_icons_widget = concrete (w);
QMenu* m = user_icons_widget->get_qmenu(); QList<QAction*>* list = user_icons_widget->get_qactionlist();
if (m) { if (list) {
replaceButtons (userToolBar, m); replaceButtons (userToolBar, list);
update_visibility(); update_visibility();
} }
} }
break; break;
case SLOT_SIDE_TOOLS: case SLOT_SIDE_TOOLS:
check_type_void (index, s); check_type_void (index, s);
{ {
side_tools_widget = concrete (w); side_tools_widget = concrete (w);
QWidget* new_qwidget = side_tools_widget->as_qwidget(); QWidget* new_qwidget = side_tools_widget->as_qwidget();
skipping to change at line 893 skipping to change at line 894
} }
} }
void void
qt_tm_widget_rep::set_full_screen(bool flag) { qt_tm_widget_rep::set_full_screen(bool flag) {
full_screen = flag; full_screen = flag;
QWidget *win = mainwindow()->window(); QWidget *win = mainwindow()->window();
if (win) { if (win) {
if (flag ) { if (flag ) {
#ifdef UNIFIED_TOOLBAR #ifdef UNIFIED_TOOLBAR
//HACK: we disable unified toolbar since otherwise if (use_unified_toolbar) {
// the application will crash when we return to normal mode //HACK: we disable unified toolbar since otherwise
// (bug in Qt? present at least with 4.7.1) // the application will crash when we return to normal mode
mainwindow()->setUnifiedTitleAndToolBarOnMac(false); // (bug in Qt? present at least with 4.7.1)
mainwindow()->centralWidget()->layout()->setContentsMargins(0,0,0,0); mainwindow()->setUnifiedTitleAndToolBarOnMac(false);
mainwindow()->centralWidget()->layout()->setContentsMargins(0,0,0,0);
}
#endif #endif
// mainwindow()->window()->setContentsMargins(0,0,0,0); // mainwindow()->window()->setContentsMargins(0,0,0,0);
//win->showFullScreen(); //win->showFullScreen();
win->setWindowState(win->windowState() ^ Qt::WindowFullScreen); win->setWindowState(win->windowState() ^ Qt::WindowFullScreen);
} else { } else {
bool cache = visibility[0]; bool cache = visibility[0];
visibility[0] = false; visibility[0] = false;
update_visibility(); update_visibility();
// win->showNormal(); // win->showNormal();
win->setWindowState(win->windowState() ^ Qt::WindowFullScreen); win->setWindowState(win->windowState() ^ Qt::WindowFullScreen);
visibility[0] = cache; visibility[0] = cache;
update_visibility(); update_visibility();
#ifdef UNIFIED_TOOLBAR #ifdef UNIFIED_TOOLBAR
mainwindow()->centralWidget()->layout()->setContentsMargins (0,1,0,0); if (use_unified_toolbar) {
//HACK: we reenable unified toolbar (see above HACK) mainwindow()->centralWidget()->layout()->setContentsMargins (0,1,0,0);
// the application will crash when we return to normal mode //HACK: we reenable unified toolbar (see above HACK)
mainwindow()->setUnifiedTitleAndToolBarOnMac(true); // the application will crash when we return to normal mode
mainwindow()->setUnifiedTitleAndToolBarOnMac(true);
}
#endif #endif
} }
} }
scrollarea()->setHorizontalScrollBarPolicy(flag ? Qt::ScrollBarAlwaysOff : Qt: :ScrollBarAsNeeded); scrollarea()->setHorizontalScrollBarPolicy(flag ? Qt::ScrollBarAlwaysOff : Qt: :ScrollBarAsNeeded);
scrollarea()->setVerticalScrollBarPolicy(flag ? Qt::ScrollBarAlwaysOff : Qt::S crollBarAsNeeded); scrollarea()->setVerticalScrollBarPolicy(flag ? Qt::ScrollBarAlwaysOff : Qt::S crollBarAsNeeded);
} }
/****************************************************************************** /******************************************************************************
* qt_tm_embedded_widget_rep * qt_tm_embedded_widget_rep
 End of changes. 23 change blocks. 
103 lines changed or deleted 110 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS