]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiView.cpp
Localize format prettyName in some more places (#11954)
[features.git] / src / frontends / qt / GuiView.cpp
index 6890c16ad4559eb9183f158a84b16b3e00d5b890..948deb9a756c8378faa666f9974db143287037bd 100644 (file)
@@ -95,6 +95,7 @@
 #include <QDropEvent>
 #include <QFuture>
 #include <QFutureWatcher>
+#include <QGroupBox>
 #include <QLabel>
 #include <QList>
 #include <QMenu>
 #include <QTimer>
 #include <QToolBar>
 #include <QUrl>
-
+#include <QWindowStateChangeEvent>
 
 
 // sync with GuiAlert.cpp
@@ -745,7 +746,7 @@ QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 static void handleExportStatus(GuiView * view, Buffer::ExportStatus status,
        string const & format)
 {
-       docstring const fmt = theFormats().prettyName(format);
+       docstring const fmt = translateIfPossible(theFormats().prettyName(format));
        docstring msg;
        switch (status) {
        case Buffer::ExportSuccess:
@@ -1401,6 +1402,49 @@ bool GuiView::event(QEvent * e)
        //case QEvent::Drop:
        //      break;
 
+       case QEvent::WindowStateChange: {
+               QWindowStateChangeEvent * ev = (QWindowStateChangeEvent*)e;
+               bool ofstate = (ev->oldState() & Qt::WindowFullScreen);
+               bool result = QMainWindow::event(e);
+               bool nfstate = (windowState() & Qt::WindowFullScreen);
+               if (!ofstate && nfstate) {
+                       LYXERR(Debug::DEBUG, "GuiView: WindowStateChange(): full-screen " << nfstate);
+                       // switch to full-screen state
+                       if (lyxrc.full_screen_statusbar)
+                               statusBar()->hide();
+                       if (lyxrc.full_screen_menubar)
+                               menuBar()->hide();
+                       if (lyxrc.full_screen_toolbars) {
+                               ToolbarMap::iterator end = d.toolbars_.end();
+                               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
+                                       if (it->second->isVisibiltyOn() && it->second->isVisible())
+                                               it->second->hide();
+                       }
+                       for (int i = 0; i != d.splitter_->count(); ++i)
+                               d.tabWorkArea(i)->setFullScreen(true);
+                       setContentsMargins(-2, -2, -2, -2);
+                       // bug 5274
+                       hideDialogs("prefs", nullptr);
+               } else if (ofstate && !nfstate) {
+                       LYXERR(Debug::DEBUG, "GuiView: WindowStateChange(): full-screen " << nfstate);
+                       // switch back from full-screen state
+                       if (lyxrc.full_screen_statusbar && !statusBar()->isVisible())
+                               statusBar()->show();
+                       if (lyxrc.full_screen_menubar && !menuBar()->isVisible())
+                               menuBar()->show();
+                       if (lyxrc.full_screen_toolbars) {
+                               ToolbarMap::iterator end = d.toolbars_.end();
+                               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
+                                       if (it->second->isVisibiltyOn() && !it->second->isVisible())
+                                               it->second->show();
+                               //updateToolbars();
+                       }
+                       for (int i = 0; i != d.splitter_->count(); ++i)
+                               d.tabWorkArea(i)->setFullScreen(false);
+                       setContentsMargins(0, 0, 0, 0);
+               }
+               return result;
+               }
        case QEvent::WindowActivate: {
                GuiView * old_view = guiApp->currentView();
                if (this == old_view) {
@@ -1996,7 +2040,9 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        }
 
        case LFUN_BUFFER_WRITE:
-               enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
+               enable = doc_buffer && (doc_buffer->isUnnamed()
+                                       || (!doc_buffer->isClean()
+                                           || cmd.argument() == "force"));
                break;
 
        //FIXME: This LFUN should be moved to GuiApplication.
@@ -2310,6 +2356,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_SERVER_GOTO_FILE_ROW:
        case LFUN_LYX_ACTIVATE:
+       case LFUN_WINDOW_RAISE:
                break;
        case LFUN_FORWARD_SEARCH:
                enable = !(lyxrc.forward_search_dvi.empty() && lyxrc.forward_search_pdf.empty());
@@ -2324,6 +2371,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setOnOff(lyxrc.spellcheck_continuously);
                break;
 
+       case LFUN_CITATION_OPEN:
+               enable = true;
+               break;
+
        default:
                return false;
        }
@@ -2485,7 +2536,7 @@ static bool import(GuiView * lv, FileName const & filename,
                if (loader_format.empty()) {
                        frontend::Alert::error(_("Couldn't import file"),
                                         bformat(_("No information for importing the format %1$s."),
-                                        theFormats().prettyName(format)));
+                                        translateIfPossible(theFormats().prettyName(format))));
                        return false;
                }
        } else
@@ -2532,13 +2583,13 @@ void GuiView::importDocument(string const & argument)
                }
 
                docstring const text = bformat(_("Select %1$s file to import"),
-                       theFormats().prettyName(format));
+                       translateIfPossible(theFormats().prettyName(format)));
 
                FileDialog dlg(toqstr(text));
                dlg.setButton1(qt_("D&ocuments"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("&Examples"), toqstr(lyxrc.example_path));
 
-               docstring filter = theFormats().prettyName(format);
+               docstring filter = translateIfPossible(theFormats().prettyName(format));
                filter += " (*.{";
                // FIXME UNICODE
                filter += from_utf8(theFormats().extensions(format));
@@ -3067,7 +3118,9 @@ bool GuiView::closeWorkArea(GuiWorkArea * wa)
                                  "  Tools->Preferences->Look&Feel->UserInterface\n"
                                ), file);
                        int ret = Alert::prompt(_("Close or hide document?"),
-                               text, 0, 1, _("&Close"), _("&Hide"));
+                               text, 0, 2, _("&Close"), _("&Hide"), _("&Cancel"));
+                       if (ret == 2)
+                               return false;
                        close_buffer = (ret == 0);
                }
        }
@@ -3104,6 +3157,14 @@ void GuiView::writeSession() const {
 
 bool GuiView::closeBufferAll()
 {
+
+       for (auto & buf : theBufferList()) {
+               if (!saveBufferIfNeeded(*buf, false)) {
+                       // Closing has been cancelled, so abort.
+                       return false;
+               }
+       }
+
        // Close the workareas in all other views
        QList<int> const ids = guiApp->viewIds();
        for (int i = 0; i != ids.size(); ++i) {
@@ -3115,9 +3176,6 @@ bool GuiView::closeBufferAll()
        if (!closeWorkAreaAll())
                return false;
 
-       // Now close the hidden buffers. We prevent hidden buffers from being
-       // dirty, so we can just close them.
-       theBufferList().closeAll();
        return true;
 }
 
@@ -3206,12 +3264,13 @@ bool GuiView::closeBuffer(Buffer & buf)
                        // Even in this case, children can be dirty (e.g.,
                        // after a label change in the master, see #11405).
                        // Therefore, check this
-                       if (closing_ && (child_buf->isClean() || child_buf->paragraphs().empty()))
+                       if (closing_ && (child_buf->isClean() || child_buf->paragraphs().empty())) {
                                // If we are in a close_event all children will be closed in some time,
                                // so no need to do it here. This will ensure that the children end up
                                // in the session file in the correct order. If we close the master
                                // buffer, we can close or release the child buffers here too.
                                continue;
+                       }
                        // Save dirty buffers also if closing_!
                        if (saveBufferIfNeeded(*child_buf, false)) {
                                child_buf->removeAutosaveFile();
@@ -3228,8 +3287,8 @@ bool GuiView::closeBuffer(Buffer & buf)
                // goto bookmark to update bookmark pit.
                // FIXME: we should update only the bookmarks related to this buffer!
                LYXERR(Debug::DEBUG, "GuiView::closeBuffer()");
-               for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
-                       guiApp->gotoBookmark(i+1, false, false);
+               for (unsigned int i = 0; i < theSession().bookmarks().size(); ++i)
+                       guiApp->gotoBookmark(i + 1, false, false);
 
                if (saveBufferIfNeeded(buf, false)) {
                        buf.removeAutosaveFile();
@@ -4500,6 +4559,12 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        activateWindow();
                        break;
 
+               case LFUN_WINDOW_RAISE:
+                       raise();
+                       activateWindow();
+                       showNormal();
+                       break;
+
                case LFUN_FORWARD_SEARCH: {
                        // it seems safe to assume we have a document buffer, since
                        // getStatus wants one.
@@ -4559,6 +4624,16 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dr.screenUpdate(Update::Force);
                        break;
 
+               case LFUN_CITATION_OPEN: {
+                       string pdfv, psv;
+                       if (theFormats().getFormat("pdf"))
+                               pdfv = theFormats().getFormat("pdf")->viewer();
+                       if (theFormats().getFormat("ps"))
+                               psv = theFormats().getFormat("ps")->viewer();
+                       frontend::showTarget(argument, pdfv, psv);
+                       break;
+               }
+
                default:
                        // The LFUN must be for one of BufferView, Buffer or Cursor;
                        // let's try that:
@@ -4604,8 +4679,8 @@ bool GuiView::lfunUiToggle(string const & ui_component)
                menuBar()->setVisible(!menuBar()->isVisible());
        } else
        if (ui_component == "frame") {
-               int l, t, r, b;
-               getContentsMargins(&l, &t, &r, &b);
+               int const l = contentsMargins().left();
+
                //are the frames in default state?
                d.current_work_area_->setFrameStyle(QFrame::NoFrame);
                if (l == 0) {
@@ -4624,35 +4699,7 @@ bool GuiView::lfunUiToggle(string const & ui_component)
 
 void GuiView::toggleFullScreen()
 {
-       if (isFullScreen()) {
-               for (int i = 0; i != d.splitter_->count(); ++i)
-                       d.tabWorkArea(i)->setFullScreen(false);
-               setContentsMargins(0, 0, 0, 0);
-               setWindowState(windowState() ^ Qt::WindowFullScreen);
-               restoreLayout();
-               menuBar()->show();
-               statusBar()->show();
-       } else {
-               // bug 5274
-               hideDialogs("prefs", nullptr);
-               for (int i = 0; i != d.splitter_->count(); ++i)
-                       d.tabWorkArea(i)->setFullScreen(true);
-               setContentsMargins(-2, -2, -2, -2);
-               saveLayout();
-               setWindowState(windowState() ^ Qt::WindowFullScreen);
-               if (lyxrc.full_screen_statusbar)
-                       statusBar()->hide();
-               if (lyxrc.full_screen_menubar)
-                       menuBar()->hide();
-               if (lyxrc.full_screen_toolbars) {
-                       ToolbarMap::iterator end = d.toolbars_.end();
-                       for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                               it->second->hide();
-               }
-       }
-
-       // give dialogs like the TOC a chance to adapt
-       updateDialogs();
+       setWindowState(windowState() ^ Qt::WindowFullScreen);
 }
 
 
@@ -4706,7 +4753,7 @@ namespace {
 char const * const dialognames[] = {
 
 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
-"citation", "compare", "comparehistory", "document", "errorlist", "ert",
+"citation", "compare", "comparehistory", "counter", "document", "errorlist", "ert",
 "external", "file", "findreplace", "findreplaceadv", "float", "graphics",
 "href", "include", "index", "index_print", "info", "listings", "label", "line",
 "log", "lyxfiles", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
@@ -4754,6 +4801,19 @@ void GuiView::resetDialogs()
 }
 
 
+void GuiView::flatGroupBoxes(const QObject * widget, bool flag)
+{
+       for (QObject * child: widget->children()) {
+               if (child->inherits("QGroupBox")) {
+                       QGroupBox * box = (QGroupBox*) child;
+                       box->setFlat(flag);
+               } else {
+                       flatGroupBoxes(child, flag);
+               }
+       }
+}
+
+
 Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
 {
        if (!isValidName(name))
@@ -4769,6 +4829,11 @@ Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
 
        Dialog * dialog = build(name);
        d.dialogs_[name].reset(dialog);
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+       // Force a uniform style for group boxes
+       // On Mac non-flat works better, on Linux flat is standard
+       flatGroupBoxes(dialog->asQWidget(), guiApp->platformName() != "cocoa");
+#endif
        if (lyxrc.allow_geometry_session)
                dialog->restoreSession();
        if (hide_it)