syncthingtray/tray/gui/traymenu.cpp
Martchus 975e86c895 Allow backend libraries to be used from other projects
So far the backend libraries' include paths were relative within this
repository. This means the header files could not be used at their
installed location.

This change replaces them with "<>" includes to fix that problem and adds
a new include directory so building everything at once still works.

With this change it should be easier to actually split some parts into
another repository if this one would become too big.
2021-01-25 19:48:11 +01:00

61 lines
1.7 KiB
C++

#include "./traymenu.h"
#include "./trayicon.h"
#include "./traywidget.h"
#include <syncthingwidgets/settings/settings.h>
#include <qtutilities/misc/dialogutils.h>
#include <QApplication>
#include <QHBoxLayout>
using namespace QtUtilities;
namespace QtGui {
TrayMenu::TrayMenu(TrayIcon *trayIcon, QWidget *parent)
: QMenu(parent)
, m_trayIcon(trayIcon)
{
setObjectName(QStringLiteral("QtGui::TrayMenu"));
auto *const menuLayout = new QHBoxLayout;
menuLayout->setContentsMargins(0, 0, 0, 0);
menuLayout->setSpacing(0);
menuLayout->addWidget(m_trayWidget = new TrayWidget(this));
setLayout(menuLayout);
setPlatformMenu(nullptr);
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
}
QSize TrayMenu::sizeHint() const
{
return Settings::values().appearance.trayMenuSize;
}
/*!
* \brief Moves the specified \a innerRect at the specified \a point into the specified \a outerRect
* by altering \a point.
*/
void moveInside(QPoint &point, const QSize &innerRect, const QRect &outerRect)
{
if (point.y() < outerRect.top()) {
point.setY(outerRect.top());
} else if (point.y() + innerRect.height() > outerRect.bottom()) {
point.setY(outerRect.bottom() - innerRect.height());
}
if (point.x() < outerRect.left()) {
point.setX(outerRect.left());
} else if (point.x() + innerRect.width() > outerRect.right()) {
point.setX(outerRect.right() - innerRect.width());
}
}
void TrayMenu::showUsingPositioningSettings()
{
resize(sizeHint());
auto pos = Settings::values().appearance.positioning.positionToUse();
moveInside(pos, size(), availableScreenGeometryAtPoint(pos));
popup(pos);
}
} // namespace QtGui