Skip to content

Commit

Permalink
Remove unused code for moving dialogs around
Browse files Browse the repository at this point in the history
CCBUG:412393
  • Loading branch information
hallarempt committed Sep 27, 2019
1 parent 36c21a9 commit 6187864
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 121 deletions.
100 changes: 0 additions & 100 deletions libs/widgets/KoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "KoDialog_p.h"

#include <QApplication>
#include <QScreen>
#include <QGuiApplication>
#include <QDesktopWidget>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QHideEvent>
Expand Down Expand Up @@ -550,104 +548,6 @@ void KoDialog::resizeLayout(QLayout *layout, int margin, int spacing) //static
}
}

static QRect screenRect(QWidget *widget, int screen)
{
QDesktopWidget *desktop = QApplication::desktop();
KConfig gc("kdeglobals", KConfig::NoGlobals);
auto screens = QGuiApplication::screens();
KConfigGroup cg(&gc, "Windows");
if (QApplication::primaryScreen()->virtualSiblings().count() &&
cg.readEntry("XineramaEnabled", true) &&
cg.readEntry("XineramaPlacementEnabled", true)) {

if (screen < 0 || screen >= screens.count()) {
if (screen == -1) {
return QGuiApplication::primaryScreen()->availableVirtualGeometry();
} else if (screen == -3) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return QGuiApplication::screenAt(QCursor::pos())->availableVirtualGeometry();
#else
screen = desktop->screenNumber(QCursor::pos());
#endif
} else {
screen = desktop->screenNumber(widget);
}
}

return QGuiApplication::screens().at(screen)->availableVirtualGeometry();
} else {
return desktop->geometry();
}
}

void KoDialog::centerOnScreen(QWidget *widget, int screen)
{
if (!widget) {
return;
}

QRect rect = screenRect(widget, screen);

widget->move(rect.center().x() - widget->width() / 2,
rect.center().y() - widget->height() / 2);
}

bool KoDialog::avoidArea(QWidget *widget, const QRect &area, int screen)
{
if (!widget) {
return false;
}

QRect fg = widget->frameGeometry();
if (!fg.intersects(area)) {
return true; // nothing to do.
}

const QRect scr = screenRect(widget, screen);
QRect avoid(area); // let's add some margin
avoid.translate(-5, -5);
avoid.setRight(avoid.right() + 10);
avoid.setBottom(avoid.bottom() + 10);

if (qMax(fg.top(), avoid.top()) <= qMin(fg.bottom(), avoid.bottom())) {
// We need to move the widget up or down
int spaceAbove = qMax(0, avoid.top() - scr.top());
int spaceBelow = qMax(0, scr.bottom() - avoid.bottom());
if (spaceAbove > spaceBelow) // where's the biggest side?
if (fg.height() <= spaceAbove) { // big enough?
fg.setY(avoid.top() - fg.height());
} else {
return false;
}
else if (fg.height() <= spaceBelow) { // big enough?
fg.setY(avoid.bottom());
} else {
return false;
}
}

if (qMax(fg.left(), avoid.left()) <= qMin(fg.right(), avoid.right())) {
// We need to move the widget left or right
const int spaceLeft = qMax(0, avoid.left() - scr.left());
const int spaceRight = qMax(0, scr.right() - avoid.right());
if (spaceLeft > spaceRight) // where's the biggest side?
if (fg.width() <= spaceLeft) { // big enough?
fg.setX(avoid.left() - fg.width());
} else {
return false;
}
else if (fg.width() <= spaceRight) { // big enough?
fg.setX(avoid.right());
} else {
return false;
}
}

widget->move(fg.x(), fg.y());

return true;
}

void KoDialog::showButtonSeparator(bool state)
{
Q_D(KoDialog);
Expand Down
21 changes: 0 additions & 21 deletions libs/widgets/KoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,27 +466,6 @@ class KRITAWIDGETS_EXPORT KoDialog : public QDialog //krazy:exclude=qclasses
*/
static void resizeLayout(QLayout *lay, int margin, int spacing);

/**
* Centers @p widget on the desktop, taking multi-head setups into
* account. If @p screen is -1, @p widget will be centered on its
* current screen (if it was shown already) or on the primary screen.
* If @p screen is -3, @p widget will be centered on the screen that
* currently contains the mouse pointer.
* @p screen will be ignored if a merged display (like Xinerama) is not
* in use, or merged display placement is not enabled in kdeglobals.
*/
static void centerOnScreen(QWidget *widget, int screen = -1);

/**
* Places @p widget so that it doesn't cover a certain @p area of the screen.
* This is typically used by the "find dialog" so that the match it finds can
* be read.
* For @p screen, see centerOnScreen
* @return true on success (widget doesn't cover area anymore, or never did),
* false on failure (not enough space found)
*/
static bool avoidArea(QWidget *widget, const QRect &area, int screen = -1);

/**
* Sets the main widget of the dialog.
*/
Expand Down

0 comments on commit 6187864

Please sign in to comment.