]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index bbd653397ce07047aa0d409973d18034e34c85a8..60a2de62657a62234c4abfa1f7211ba94ead1de6 100644 (file)
@@ -47,6 +47,9 @@
 #include <QContextMenuEvent>
 #include <QInputContext>
 #include <QHelpEvent>
+#ifdef Q_WS_MAC
+#include <QMacStyle>
+#endif
 #include <QMainWindow>
 #include <QPainter>
 #include <QPalette>
@@ -248,6 +251,11 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        setAcceptDrops(true);
        setMouseTracking(true);
        setMinimumSize(100, 70);
+#ifdef Q_WS_MACX
+       setFrameStyle(QFrame::NoFrame); 
+#else
+       setFrameStyle(QFrame::Box);
+#endif
        updateWindowTitle();
 
        viewport()->setAutoFillBackground(false);
@@ -298,7 +306,11 @@ void GuiWorkArea::setFullScreen(bool full_screen)
                if (lyxrc.full_screen_scrollbar)
                        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        } else {
+#ifdef Q_WS_MACX
+               setFrameStyle(QFrame::NoFrame); 
+#else
                setFrameStyle(QFrame::Box);
+#endif
                setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        }
 }
@@ -612,7 +624,9 @@ void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
 
 void GuiWorkArea::focusInEvent(QFocusEvent * e)
 {
-       lyx_view_->setCurrentWorkArea(this);
+       if (lyx_view_->currentWorkArea() != this)
+               lyx_view_->setCurrentWorkArea(this);
+
        // Repaint the whole screen.
        // Note: this is different from redraw() as only the backing pixmap
        // will be redrawn, which is cheap.
@@ -1113,8 +1127,40 @@ bool GuiWorkArea::isFullScreen()
 //
 ////////////////////////////////////////////////////////////////////
 
+#ifdef Q_WS_MACX
+class NoTabFrameMacStyle : public QMacStyle {
+public:
+       ///
+       QRect subElementRect(SubElement element, const QStyleOption * option,
+                            const QWidget * widget = 0 ) const 
+       {
+               QRect rect = QMacStyle::subElementRect(element, option, widget);
+               bool noBar = static_cast<QTabWidget const *>(widget)->count() <= 1;
+               
+               // The Qt Mac style puts the contents into a 3 pixel wide box
+               // which looks very ugly and not like other Mac applications.
+               // Hence we remove this here, and moreover the 16 pixel round
+               // frame above if the tab bar is hidden.
+               if (element == QStyle::SE_TabWidgetTabContents) {
+                       rect.adjust(- rect.left(), 0, rect.left(), 0);
+                       if (noBar)
+                               rect.setTop(0);
+               }
+
+               return rect;
+       }
+};
+
+NoTabFrameMacStyle noTabFramemacStyle;
+#endif
+
+
 TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
 {
+#ifdef Q_WS_MACX
+       setStyle(&noTabFramemacStyle);
+#endif
+
        QPalette pal = palette();
        pal.setColor(QPalette::Active, QPalette::Button,
                pal.color(QPalette::Active, QPalette::Window));
@@ -1127,7 +1173,7 @@ TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
                this, SLOT(on_currentTabChanged(int)));
 
        QToolButton * closeBufferButton = new QToolButton(this);
-    closeBufferButton->setPalette(pal);
+       closeBufferButton->setPalette(pal);
        // FIXME: rename the icon to closebuffer.png
        closeBufferButton->setIcon(QIcon(":/images/closetab.png"));
        closeBufferButton->setText("Close File");
@@ -1140,7 +1186,7 @@ TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
        setCornerWidget(closeBufferButton, Qt::TopRightCorner);
 
        QToolButton * closeTabButton = new QToolButton(this);
-    closeTabButton->setPalette(pal);
+       closeTabButton->setPalette(pal);
        closeTabButton->setIcon(QIcon(":/images/hidetab.png"));
        closeTabButton->setText("Hide tab");
        closeTabButton->setAutoRaise(true);