]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Show icon overlays in the Informationen Panel.
[dolphin.git] / src / dolphinmainwindow.cpp
index dbb46a239d494dbdaa2cf5ae6edf001d16177686..0f075a11cb4d0456eb60f989b6b56e2fbc0043a2 100644 (file)
@@ -28,7 +28,6 @@
 #include "dolphincontextmenu.h"
 #include "dolphinnewfilemenu.h"
 #include "dolphinviewcontainer.h"
-#include "mainwindowadaptor.h"
 #ifdef HAVE_NEPOMUK
     #include "panels/search/searchpanel.h"
     #include <Nepomuk/ResourceManager>
@@ -36,6 +35,7 @@
 #include "panels/folders/folderspanel.h"
 #include "panels/places/placespanel.h"
 #include "panels/information/informationpanel.h"
+#include "search/dolphinsearchbox.h"
 #include "search/dolphinsearchinformation.h"
 #include "settings/dolphinsettings.h"
 #include "settings/dolphinsettingsdialog.h"
@@ -122,18 +122,17 @@ struct ClosedTab
 };
 Q_DECLARE_METATYPE(ClosedTab)
 
-DolphinMainWindow::DolphinMainWindow(int id) :
+DolphinMainWindow::DolphinMainWindow() :
     KXmlGuiWindow(0),
     m_newFileMenu(0),
     m_tabBar(0),
     m_activeViewContainer(0),
     m_centralWidgetLayout(0),
-    m_id(id),
     m_tabIndex(0),
     m_viewTab(),
     m_actionHandler(0),
     m_remoteEncoding(0),
-    m_settingsDialog(0),
+    m_settingsDialog(),
     m_toolBarSpacer(0),
     m_openToolBarMenuButton(0),
     m_updateToolBarTimer(0),
@@ -149,9 +148,6 @@ DolphinMainWindow::DolphinMainWindow(int id) :
 
     m_viewTab.append(ViewTab());
 
-    new MainWindowAdaptor(this);
-    QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
-
     KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface());
 
@@ -167,11 +163,106 @@ DolphinMainWindow::DolphinMainWindow(int id) :
             this, SLOT(showErrorMessage(const QString&)));
     connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
             this, SLOT(showErrorMessage(const QString&)));
+
+    const DolphinSettings& settings = DolphinSettings::instance();
+
+    GeneralSettings* generalSettings = settings.generalSettings();
+    const bool firstRun = generalSettings->firstRun();
+    if (firstRun) {
+        generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
+    }
+
+    setAcceptDrops(true);
+
+    m_viewTab[m_tabIndex].splitter = new QSplitter(this);
+    m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
+
+    setupActions();
+
+    const KUrl homeUrl(generalSettings->homeUrl());
+    setUrlAsCaption(homeUrl);
+    m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
+    connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
+    connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
+
+    m_viewTab[m_tabIndex].primaryView = createViewContainer(homeUrl, m_viewTab[m_tabIndex].splitter);
+
+    m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
+    connectViewSignals(m_activeViewContainer);
+    DolphinView* view = m_activeViewContainer->view();
+    m_activeViewContainer->show();
+    m_actionHandler->setCurrentView(view);
+
+    m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
+    connect(this, SIGNAL(urlChanged(const KUrl&)),
+            m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
+
+    m_tabBar = new KTabBar(this);
+    m_tabBar->setMovable(true);
+    m_tabBar->setTabsClosable(true);
+    connect(m_tabBar, SIGNAL(currentChanged(int)),
+            this, SLOT(setActiveTab(int)));
+    connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
+            this, SLOT(closeTab(int)));
+    connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
+            this, SLOT(openTabContextMenu(int, const QPoint&)));
+    connect(m_tabBar, SIGNAL(newTabRequest()),
+            this, SLOT(openNewTab()));
+    connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
+            this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
+    connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
+            this, SLOT(closeTab(int)));
+    connect(m_tabBar, SIGNAL(tabMoved(int, int)),
+            this, SLOT(slotTabMoved(int, int)));
+    connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
+            this, SLOT(tabDropEvent(int, QDropEvent*)));
+
+    m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
+
+    QWidget* centralWidget = new QWidget(this);
+    m_centralWidgetLayout = new QVBoxLayout(centralWidget);
+    m_centralWidgetLayout->setSpacing(0);
+    m_centralWidgetLayout->setMargin(0);
+    m_centralWidgetLayout->addWidget(m_tabBar);
+    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
+
+    setCentralWidget(centralWidget);
+    setupDockWidgets();
+    emit urlChanged(homeUrl);
+
+    setupGUI(Keys | Save | Create | ToolBar);
+    stateChanged("new_file");
+
+    QClipboard* clipboard = QApplication::clipboard();
+    connect(clipboard, SIGNAL(dataChanged()),
+            this, SLOT(updatePasteAction()));
+
+    if (generalSettings->splitView()) {
+        toggleSplitView();
+    }
+    updateEditActions();
+    updateViewActions();
+    updateGoActions();
+
+    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
+    showFilterBarAction->setChecked(generalSettings->filterBar());
+
+    if (firstRun) {
+        menuBar()->setVisible(false);
+        // Assure a proper default size if Dolphin runs the first time
+        resize(750, 500);
+    }
+
+    const bool showMenu = !menuBar()->isHidden();
+    QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
+    showMenuBarAction->setChecked(showMenu);  // workaround for bug #171080
+    if (!showMenu) {
+        createToolBarMenuButton();
+    }
 }
 
 DolphinMainWindow::~DolphinMainWindow()
 {
-    DolphinApplication::app()->removeMainWindow(this);
 }
 
 void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
@@ -204,7 +295,7 @@ void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
         }
     }
 
-    // remove the previously opened tabs
+    // Remove the previously opened tabs
     for (int i = 0; i < oldOpenTabsCount; ++i) {
         closeTab(0);
     }
@@ -276,39 +367,6 @@ void DolphinMainWindow::showCommand(CommandType command)
     }
 }
 
-void DolphinMainWindow::refreshViews()
-{
-    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
-
-    // remember the current active view, as because of
-    // the refreshing the active view might change to
-    // the secondary view
-    DolphinViewContainer* activeViewContainer = m_activeViewContainer;
-
-    const int tabCount = m_viewTab.count();
-    for (int i = 0; i < tabCount; ++i) {
-        m_viewTab[i].primaryView->refresh();
-        if (m_viewTab[i].secondaryView) {
-            m_viewTab[i].secondaryView->refresh();
-        }
-    }
-
-    setActiveViewContainer(activeViewContainer);
-
-    const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
-    if (generalSettings->modifiedStartupSettings()) {
-        // The startup settings have been changed by the user (see bug #254947).
-        // Synchronize the split-view setting with the active view:
-        const bool splitView = generalSettings->splitView();
-        const ViewTab& activeTab = m_viewTab[m_tabIndex];
-        const bool toggle =    ( splitView && !activeTab.secondaryView)
-                            || (!splitView &&  activeTab.secondaryView);
-        if (toggle) {
-            toggleSplitView();
-        }
-    }
-}
-
 void DolphinMainWindow::pasteIntoFolder()
 {
     m_activeViewContainer->view()->pasteIntoFolder();
@@ -397,7 +455,7 @@ void DolphinMainWindow::updateFilterBarAction(bool show)
 
 void DolphinMainWindow::openNewMainWindow()
 {
-    DolphinApplication::app()->createMainWindow()->show();
+    KRun::run("dolphin", KUrl::List(), this);
 }
 
 void DolphinMainWindow::openNewTab()
@@ -507,9 +565,7 @@ void DolphinMainWindow::openInNewWindow()
     }
 
     if (!newWindowUrl.isEmpty()) {
-        DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
-        window->changeUrl(newWindowUrl);
-        window->show();
+        KRun::run("dolphin", KUrl::List() << newWindowUrl, this);
     }
 }
 
@@ -766,6 +822,23 @@ void DolphinMainWindow::find()
     m_activeViewContainer->setSearchModeEnabled(true);
 }
 
+void DolphinMainWindow::slotSearchLocationChanged()
+{
+#ifdef HAVE_NEPOMUK
+    QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
+    if (!searchDock) {
+        return;
+    }
+
+    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
+    if (searchPanel) {
+        searchPanel->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
+                                       ? SearchPanel::FromCurrentDir
+                                       : SearchPanel::Everywhere);
+    }
+#endif
+}
+
 void DolphinMainWindow::updatePasteAction()
 {
     QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
@@ -1042,11 +1115,13 @@ void DolphinMainWindow::editSettings()
 {
     if (!m_settingsDialog) {
         const KUrl url = activeViewContainer()->url();
-        m_settingsDialog = new DolphinSettingsDialog(url, this);
-        m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
-        m_settingsDialog->show();
+        DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
+        connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
+        settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
+        settingsDialog->show();
+        m_settingsDialog = settingsDialog;
     } else {
-        m_settingsDialog->raise();
+        m_settingsDialog.data()->raise();
     }
 }
 
@@ -1153,25 +1228,20 @@ void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
         openNewTab(url);
         m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
     } else if (selectedAction == detachTabAction) {
+        const QString separator(QLatin1Char(' '));
+        QString command = QLatin1String("dolphin");
+
         const ViewTab& tab = m_viewTab[index];
         Q_ASSERT(tab.primaryView);
-        const KUrl primaryUrl = tab.primaryView->url();
-        DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
-        window->changeUrl(primaryUrl);
 
+        command += separator + tab.primaryView->url().url();
         if (tab.secondaryView) {
-            const KUrl secondaryUrl = tab.secondaryView->url();
-            if (!window->m_viewTab[0].secondaryView) {
-                window->toggleSplitView();
-            }
-            window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
-            if (tab.primaryView->isActive()) {
-                window->m_viewTab[0].primaryView->setActive(true);
-            } else {
-                window->m_viewTab[0].secondaryView->setActive(true);
-            }
+            command += separator + tab.secondaryView->url().url();
+            command += separator + QLatin1String("-split");
         }
-        window->show();
+
+        KRun::runCommand(command, this);
+
         closeTab(index);
     } else if (selectedAction == closeOtherTabsAction) {
         const int count = m_tabBar->count();
@@ -1255,9 +1325,8 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
 {
 #ifdef HAVE_NEPOMUK
-    const KUrl url = m_activeViewContainer->url();
     const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
-    if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) {
+    if (!searchInfo.isIndexingEnabled()) {
         return;
     }
 
@@ -1279,17 +1348,20 @@ void DolphinMainWindow::slotSearchModeChanged(bool enabled)
     }
 
     SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
-    if (searchPanel) {
-        // Per default any search-operation triggered by the Search Panel is done
-        // "Everywhere".
-        SearchPanel::SearchMode searchMode = SearchPanel::Everywhere;
-
-        if (enabled && (SearchSettings::location() == QLatin1String("FromHere"))) {
-            // Only if the search-mode is enabled it is visible for the user whether
-            // a searching is done "Everywhere" or "From Here" (= current directory).
-            searchMode = SearchPanel::FromCurrentDir;
+    if (!searchPanel) {
+        return;
+    }
+
+    if (enabled) {
+        SearchPanel::SearchLocation searchLocation = SearchPanel::Everywhere;
+        const KUrl url = m_activeViewContainer->url();
+        const bool isSearchUrl = (url.protocol() == QLatin1String("nepomuksearch"));
+        if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl)) {
+            searchLocation = SearchPanel::FromCurrentDir;
         }
-        searchPanel->setSearchMode(searchMode);
+        searchPanel->setSearchLocation(searchLocation);
+    } else {
+        searchPanel->setSearchLocation(SearchPanel::Everywhere);
     }
 #else
     Q_UNUSED(enabled);
@@ -1306,9 +1378,7 @@ void DolphinMainWindow::openContextMenu(const KFileItem& item,
 
     switch (command) {
     case DolphinContextMenu::OpenParentFolderInNewWindow: {
-        DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
-        window->changeUrl(item.url().upUrl());
-        window->show();
+        KRun::run("dolphin", KUrl::List() << item.url().upUrl(), this);
         break;
     }
 
@@ -1409,6 +1479,8 @@ void DolphinMainWindow::updateToolBarMenu()
     connect(menu, SIGNAL(aboutToHide()), helpMenu, SLOT(deleteLater()));
     helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::HelpContents)));
     helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::WhatsThis)));
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ReportBug)));
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
     helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutApp)));
     helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutKDE)));
     menu->addMenu(helpMenu);
@@ -1443,107 +1515,6 @@ void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize& iconSize)
     }
 }
 
-void DolphinMainWindow::init()
-{
-    DolphinSettings& settings = DolphinSettings::instance();
-
-    // Check whether Dolphin runs the first time. If yes then
-    // a proper default window size is given at the end of DolphinMainWindow::init().
-    GeneralSettings* generalSettings = settings.generalSettings();
-    const bool firstRun = generalSettings->firstRun();
-    if (firstRun) {
-        generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
-    }
-
-    setAcceptDrops(true);
-
-    m_viewTab[m_tabIndex].splitter = new QSplitter(this);
-    m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
-
-    setupActions();
-
-    const KUrl homeUrl(generalSettings->homeUrl());
-    setUrlAsCaption(homeUrl);
-    m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
-    connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
-    connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
-
-    m_viewTab[m_tabIndex].primaryView = createViewContainer(homeUrl, m_viewTab[m_tabIndex].splitter);
-
-    m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
-    connectViewSignals(m_activeViewContainer);
-    DolphinView* view = m_activeViewContainer->view();
-    m_activeViewContainer->show();
-    m_actionHandler->setCurrentView(view);
-
-    m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
-    connect(this, SIGNAL(urlChanged(const KUrl&)),
-            m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
-
-    m_tabBar = new KTabBar(this);
-    m_tabBar->setMovable(true);
-    m_tabBar->setTabsClosable(true);
-    connect(m_tabBar, SIGNAL(currentChanged(int)),
-            this, SLOT(setActiveTab(int)));
-    connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
-            this, SLOT(closeTab(int)));
-    connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
-            this, SLOT(openTabContextMenu(int, const QPoint&)));
-    connect(m_tabBar, SIGNAL(newTabRequest()),
-            this, SLOT(openNewTab()));
-    connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
-            this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
-    connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
-            this, SLOT(closeTab(int)));
-    connect(m_tabBar, SIGNAL(tabMoved(int, int)),
-            this, SLOT(slotTabMoved(int, int)));
-    connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
-            this, SLOT(tabDropEvent(int, QDropEvent*)));
-
-    m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
-
-    QWidget* centralWidget = new QWidget(this);
-    m_centralWidgetLayout = new QVBoxLayout(centralWidget);
-    m_centralWidgetLayout->setSpacing(0);
-    m_centralWidgetLayout->setMargin(0);
-    m_centralWidgetLayout->addWidget(m_tabBar);
-    m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
-
-    setCentralWidget(centralWidget);
-    setupDockWidgets();
-    emit urlChanged(homeUrl);
-
-    setupGUI(Keys | Save | Create | ToolBar);
-    stateChanged("new_file");
-
-    QClipboard* clipboard = QApplication::clipboard();
-    connect(clipboard, SIGNAL(dataChanged()),
-            this, SLOT(updatePasteAction()));
-
-    if (generalSettings->splitView()) {
-        toggleSplitView();
-    }
-    updateEditActions();
-    updateViewActions();
-    updateGoActions();
-
-    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
-    showFilterBarAction->setChecked(generalSettings->filterBar());
-
-    if (firstRun) {
-        menuBar()->setVisible(false);
-        // Assure a proper default size if Dolphin runs the first time
-        resize(750, 500);
-    }
-
-    const bool showMenu = !menuBar()->isHidden();
-    QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
-    showMenuBarAction->setChecked(showMenu);  // workaround for bug #171080
-    if (!showMenu) {
-        createToolBarMenuButton();
-    }
-}
-
 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
 {
     Q_ASSERT(viewContainer);
@@ -1831,6 +1802,8 @@ void DolphinMainWindow::setupDockWidgets()
     terminalDock->setWidget(terminalPanel);
 
     connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
+    connect(terminalDock, SIGNAL(visibilityChanged(bool)),
+            terminalPanel, SLOT(dockVisibilityChanged()));
 
     QAction* terminalAction = terminalDock->toggleViewAction();
     terminalAction->setShortcut(Qt::Key_F4);
@@ -2070,6 +2043,39 @@ void DolphinMainWindow::rememberClosedTab(int index)
     KAcceleratorManager::manage(tabsMenu);
 }
 
+void DolphinMainWindow::refreshViews()
+{
+    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
+
+    // remember the current active view, as because of
+    // the refreshing the active view might change to
+    // the secondary view
+    DolphinViewContainer* activeViewContainer = m_activeViewContainer;
+
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        m_viewTab[i].primaryView->refresh();
+        if (m_viewTab[i].secondaryView) {
+            m_viewTab[i].secondaryView->refresh();
+        }
+    }
+
+    setActiveViewContainer(activeViewContainer);
+
+    const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
+    if (generalSettings->modifiedStartupSettings()) {
+        // The startup settings have been changed by the user (see bug #254947).
+        // Synchronize the split-view setting with the active view:
+        const bool splitView = generalSettings->splitView();
+        const ViewTab& activeTab = m_viewTab[m_tabIndex];
+        const bool toggle =    ( splitView && !activeTab.secondaryView)
+                            || (!splitView &&  activeTab.secondaryView);
+        if (toggle) {
+            toggleSplitView();
+        }
+    }
+}
+
 void DolphinMainWindow::clearStatusBar()
 {
     m_activeViewContainer->statusBar()->clear();
@@ -2084,6 +2090,10 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
     connect(container, SIGNAL(searchModeChanged(bool)),
             this, SLOT(slotSearchModeChanged(bool)));
 
+    const DolphinSearchBox* searchBox = container->searchBox();
+    connect(searchBox, SIGNAL(searchLocationChanged(SearchLocation)),
+            this, SLOT(slotSearchLocationChanged()));
+
     DolphinView* view = container->view();
     connect(view, SIGNAL(selectionChanged(KFileItemList)),
             this, SLOT(slotSelectionChanged(KFileItemList)));
@@ -2259,15 +2269,15 @@ void ToolBarMenu::showEvent(QShowEvent* event)
     // Assure that the menu is not shown outside the screen boundaries and
     // that it does not overlap with the parent button.
     const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos());
-    if (pos.x() < 0) {
-        pos.rx() = 0;
-    } else if (pos.x() + width() >= screen.width()) {
-        pos.rx() = screen.width() - width();
+    if (pos.x() < screen.x()) {
+        pos.rx() = screen.x();
+    } else if (pos.x() + width() > screen.x() + screen.width()) {
+        pos.rx() = screen.x() + screen.width() - width();
     }
 
-    if (pos.y() < 0) {
-        pos.ry() = 0;
-    } else if (pos.y() + height() >= screen.height()) {
+    if (pos.y() < screen.y()) {
+        pos.ry() = screen.y();
+    } else if (pos.y() + height() > screen.y() + screen.height()) {
         pos.ry() = button->mapToGlobal(QPoint(0, 0)).y() - height();
     }