reduced number of calls to syncGeometry

pull/1/head
Johan Smith Agudelo Rodriguez 8 years ago
parent 60f6f8d942
commit dd7009e96e

@ -46,7 +46,7 @@ namespace Latte {
DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
: PlasmaQuick::ContainmentView(corona),
m_docksCount(0),
m_contextMenu(nullptr)
m_contextMenu(nullptr)
{
setVisible(false);
setTitle(corona->kPackage().metadata().name());
@ -62,23 +62,23 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
adaptToScreen(targetScreen);
else
adaptToScreen(qGuiApp->primaryScreen());
connect(this, &DockView::containmentChanged
, this, [&]() {
if (!containment())
return;
if (!m_visibility) {
m_visibility = new VisibilityManager(this);
}
QAction *lockWidgetsAction = containment()->actions()->action("lock widgets");
containment()->actions()->removeAction(lockWidgetsAction);
QAction *removeAction = containment()->actions()->action("remove");
removeAction->setVisible(false);
//containment()->actions()->removeAction(removeAction);
//FIX: hide and not delete in order to disable a nasty behavior from
//ContainmentInterface. If only one action exists for containment the
//this action is triggered directly
@ -87,9 +87,9 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
//containment()->actions()->removeAction(addWidgetsAction);
}, Qt::DirectConnection);
DockCorona *dcorona = qobject_cast<DockCorona *>(this->corona());
if (dcorona) {
connections << connect(dcorona, &DockCorona::containmentsNoChanged, this, &DockView::updateDocksCount);
}
@ -98,13 +98,13 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
DockView::~DockView()
{
qDebug() << "dock view deleting...";
foreach (auto &var, connections) {
QObject::disconnect(var);
}
qDebug() << "dock view connections deleted...";
if (m_visibility) {
m_visibility.clear();
}
@ -116,12 +116,13 @@ void DockView::init()
connect(this, &DockView::screenGeometryChanged, this, &DockView::syncGeometry, Qt::QueuedConnection);
connect(this, &QQuickWindow::widthChanged, this, &DockView::widthChanged);
connect(this, &QQuickWindow::heightChanged, this, &DockView::heightChanged);
connect(this, &DockView::locationChanged, this, &DockView::syncGeometry);
connect(this, &QQuickWindow::xChanged, this, &DockView::syncGeometry);
connect(this, &QQuickWindow::yChanged, this, &DockView::syncGeometry);
connect(this, &QQuickWindow::xChanged, this, &DockView::updateAbsDockGeometry);
connect(this, &QQuickWindow::yChanged, this, &DockView::updateAbsDockGeometry);
connect(this, &DockView::locationChanged, this, [&]() {
updateFormFactor();
syncGeometry();
});
connect(this, &DockView::localDockGeometryChanged, this, &DockView::syncGeometry);
connect(this, &DockView::localDockGeometryChanged, this, &DockView::updateAbsDockGeometry);
connect(&timerSyncGeometry, &QTimer::timeout, this, &DockView::updatePosition);
@ -144,10 +145,10 @@ void DockView::adaptToScreen(QScreen *screen)
m_maxLength = screen->size().height();
else
m_maxLength = screen->size().width();
if (containment())
containment()->reactToScreenChange();
syncGeometry();
}
@ -194,7 +195,7 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet)
{
if (!applet || !applet->containment())
return;
Plasma::Containment *c = qobject_cast<Plasma::Containment *>(applet);
if (m_configView && c && c->isContainment() && c == containment()) {
@ -218,7 +219,7 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet)
}
bool delayConfigView = false;
if (c && containment() && c->isContainment() && c->id() == containment()->id()) {
m_configView = new DockConfigView(c, this);
delayConfigView = true;
@ -227,7 +228,7 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet)
}
m_configView.data()->init();
if (!delayConfigView) {
m_configView.data()->show();
} else {
@ -274,7 +275,7 @@ void DockView::updateAbsDockGeometry()
{
if (!m_visibility)
return;
QRect absoluteGeometry {x() + m_localDockGeometry.x(), y() + m_localDockGeometry.y(), m_localDockGeometry.width(), m_localDockGeometry.height()};
m_visibility->updateDockGeometry(absoluteGeometry);
}
@ -283,41 +284,41 @@ void DockView::updatePosition()
{
if (!containment())
return;
const QRect screenGeometry = screen()->geometry();
QPoint position;
qDebug() << "current dock geometry: " << geometry();
position = {0, 0};
m_maxLength = screenGeometry.width();
switch (location()) {
case Plasma::Types::TopEdge:
position = {screenGeometry.x(), screenGeometry.y()};
m_maxLength = screenGeometry.width();
break;
case Plasma::Types::BottomEdge:
position = {screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - height()};
m_maxLength = screenGeometry.width();
break;
case Plasma::Types::RightEdge:
position = {screenGeometry.x() + screenGeometry.width() - width(), screenGeometry.y()};
m_maxLength = screenGeometry.height();
break;
case Plasma::Types::LeftEdge:
position = {screenGeometry.x(), screenGeometry.y()};
m_maxLength = screenGeometry.height();
break;
default:
qWarning() << "wrong location, couldn't update the panel position"
<< location();
}
emit maxLengthChanged();
setPosition(position);
@ -326,7 +327,6 @@ void DockView::updatePosition()
inline void DockView::syncGeometry()
{
updateFormFactor();
resizeWindow();
updatePosition();
updateAbsDockGeometry();
@ -349,16 +349,16 @@ int DockView::docksCount() const
void DockView::updateDocksCount()
{
DockCorona *corona = qobject_cast<DockCorona *>(this->corona());
if (corona) {
int no = corona->numDocks();
if (no == m_docksCount) {
return;
}
m_docksCount = no;
emit docksCountChanged();
}
}
@ -367,18 +367,18 @@ void DockView::updateFormFactor()
{
if (!containment())
return;
switch (location()) {
case Plasma::Types::TopEdge:
case Plasma::Types::BottomEdge:
containment()->setFormFactor(Plasma::Types::Horizontal);
break;
case Plasma::Types::LeftEdge:
case Plasma::Types::RightEdge:
containment()->setFormFactor(Plasma::Types::Vertical);
break;
default:
qWarning() << "wrong location, couldn't update the panel position"
<< location();
@ -394,7 +394,7 @@ void DockView::setMaxThickness(int thickness)
{
if (m_maxThickness == thickness)
return;
m_maxThickness = thickness;
syncGeometry();
emit maxThicknessChanged();
@ -409,12 +409,12 @@ void DockView::setLength(int length)
{
if (m_length == length)
return;
if (length > m_maxLength)
m_length = m_maxLength;
else
m_length = length;
syncGeometry();
emit lengthChanged();
}
@ -428,7 +428,7 @@ void DockView::setMaxLength(int maxLength)
{
if (m_maxLength == maxLength)
return;
m_maxLength = maxLength;
emit maxLengthChanged();
}
@ -443,7 +443,7 @@ void DockView::setMaskArea(QRect area)
{
if (m_maskArea == area)
return;
m_maskArea = area;
setMask(m_maskArea);
@ -456,12 +456,12 @@ bool DockView::tasksPresent()
{
foreach (Plasma::Applet *applet, containment()->applets()) {
KPluginMetaData meta = applet->kPackage().metadata();
if (meta.pluginId() == "org.kde.latte.plasmoid") {
return true;
}
}
return false;
}
@ -493,12 +493,12 @@ QList<int> DockView::freeEdges() const
void DockView::closeApplication()
{
DockCorona *corona = qobject_cast<DockCorona *>(this->corona());
if (corona) {
//m_configView->hide();
if (m_configView)
m_configView->deleteLater();
corona->closeApplication();
}
}
@ -506,35 +506,35 @@ void DockView::closeApplication()
QVariantList DockView::containmentActions()
{
QVariantList actions;
/*if (containment()->corona()->immutability() != Plasma::Types::Mutable) {
return actions;
}*/
//FIXME: the trigger string it should be better to be supported this way
//const QString trigger = Plasma::ContainmentActions::eventToString(event);
const QString trigger = "RightButton;NoModifier";
Plasma::ContainmentActions *plugin = containment()->containmentActions().value(trigger);
if (!plugin) {
return actions;
}
if (plugin->containment() != containment()) {
plugin->setContainment(containment());
// now configure it
KConfigGroup cfg(containment()->corona()->config(), "ActionPlugins");
cfg = KConfigGroup(&cfg, QString::number(containment()->containmentType()));
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
}
foreach (QAction *ac, plugin->contextualActions()) {
actions << QVariant::fromValue<QAction *>(ac);
}
return actions;
}
@ -543,22 +543,22 @@ QVariantList DockView::containmentActions()
void DockView::addAppletItem(QObject *item)
{
PlasmaQuick::AppletQuickItem *dynItem = qobject_cast<PlasmaQuick::AppletQuickItem *>(item);
if (!dynItem || m_appletItems.contains(dynItem)) {
return;
}
m_appletItems.append(dynItem);
}
void DockView::removeAppletItem(QObject *item)
{
PlasmaQuick::AppletQuickItem *dynItem = qobject_cast<PlasmaQuick::AppletQuickItem *>(item);
if (!dynItem) {
return;
}
m_appletItems.removeAll(dynItem);
}
@ -574,9 +574,9 @@ void DockView::mouseReleaseEvent(QMouseEvent *event)
if (!event || !containment()) {
return;
}
PlasmaQuick::ContainmentView::mouseReleaseEvent(event);
event->setAccepted(containment()->containmentActions().contains(Plasma::ContainmentActions::eventToString(event)));
}
@ -585,9 +585,9 @@ void DockView::mousePressEvent(QMouseEvent *event)
if (!event || !containment()) {
return;
}
// PlasmaQuick::ContainmentView::mousePressEvent(event);
//even if the menu is executed synchronously, other events may be processed
//by the qml incubator when plasma is loading, so we need to guard there
if (m_contextMenu) {
@ -595,20 +595,20 @@ void DockView::mousePressEvent(QMouseEvent *event)
PlasmaQuick::ContainmentView::mousePressEvent(event);
return;
}
//qDebug() << "1...";
const QString trigger = Plasma::ContainmentActions::eventToString(event);
if (trigger == "RightButton;NoModifier") {
Plasma::ContainmentActions *plugin = containment()->containmentActions().value(trigger);
if (!plugin || plugin->contextualActions().isEmpty()) {
event->setAccepted(false);
return;
}
//qDebug() << "2...";
//the plugin can be a single action or a context menu
//Don't have an action list? execute as single action
//and set the event position as action data
@ -619,12 +619,12 @@ void DockView::mousePressEvent(QMouseEvent *event)
event->accept();
return;
}*/
//qDebug() << "3...";
//FIXME: very inefficient appletAt() implementation
Plasma::Applet *applet = 0;
foreach (PlasmaQuick::AppletQuickItem *ai, m_appletItems) {
if (ai && ai->isVisible() && ai->contains(ai->mapFromItem(contentItem(), event->pos()))) {
applet = ai->applet();
@ -633,36 +633,36 @@ void DockView::mousePressEvent(QMouseEvent *event)
ai = 0;
}
}
if (applet) {
KPluginMetaData meta = applet->kPackage().metadata();
if ((meta.pluginId() != "org.kde.plasma.systemtray") &&
(meta.pluginId() != "org.kde.latte.plasmoid")) {
//qDebug() << "4...";
QMenu *desktopMenu = new QMenu;
desktopMenu->setAttribute(Qt::WA_DeleteOnClose);
m_contextMenu = desktopMenu;
if (this->mouseGrabberItem()) {
//workaround, this fixes for me most of the right click menu behavior
if (applet) {
KPluginMetaData meta = applet->kPackage().metadata();
//gives the systemtray direct right click behavior for its applets
if (meta.pluginId() != "org.kde.plasma.systemtray") {
this->mouseGrabberItem()->ungrabMouse();
}
}
return;
}
//qDebug() << "5...";
if (applet) {
emit applet->contextualActionsAboutToShow();
addAppletActions(desktopMenu, applet, event);
@ -670,60 +670,60 @@ void DockView::mousePressEvent(QMouseEvent *event)
emit containment()->contextualActionsAboutToShow();
addContainmentActions(desktopMenu, event);
}
//qDebug() << "6...";
//this is a workaround where Qt now creates the menu widget
//in .exec before oxygen can polish it and set the following attribute
desktopMenu->setAttribute(Qt::WA_TranslucentBackground);
//end workaround
QPoint pos = event->globalPos();
if (applet) {
desktopMenu->adjustSize();
if (screen()) {
const QRect scr = screen()->geometry();
int smallStep = 3;
int x = event->globalPos().x() + smallStep;
int y = event->globalPos().y() + smallStep;
//qDebug()<<x << " - "<<y;
if (event->globalPos().x() > scr.center().x()) {
x = event->globalPos().x() - desktopMenu->width() - smallStep;
}
if (event->globalPos().y() > scr.center().y()) {
y = event->globalPos().y() - desktopMenu->height() - smallStep;
}
pos = QPoint(x, y);
}
}
//qDebug() << "7...";
if (desktopMenu->isEmpty()) {
delete desktopMenu;
event->accept();
return;
}
connect(desktopMenu, SIGNAL(aboutToHide()), this, SLOT(menuAboutToHide()));
m_visibility->setBlockHiding(true);
desktopMenu->popup(pos);
event->setAccepted(true);
return;
}
}
}
PlasmaQuick::ContainmentView::mousePressEvent(event);
}
@ -732,51 +732,51 @@ void DockView::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEve
if (!containment()) {
return;
}
foreach (QAction *action, applet->contextualActions()) {
if (action) {
desktopMenu->addAction(action);
}
}
if (!applet->failedToLaunch()) {
QAction *runAssociatedApplication = applet->actions()->action(QStringLiteral("run associated application"));
if (runAssociatedApplication && runAssociatedApplication->isEnabled()) {
desktopMenu->addAction(runAssociatedApplication);
}
QAction *configureApplet = applet->actions()->action(QStringLiteral("configure"));
if (configureApplet && configureApplet->isEnabled()) {
desktopMenu->addAction(configureApplet);
}
QAction *appletAlternatives = applet->actions()->action(QStringLiteral("alternatives"));
if (appletAlternatives && appletAlternatives->isEnabled()) {
desktopMenu->addAction(appletAlternatives);
}
}
QMenu *containmentMenu = new QMenu(i18nc("%1 is the name of the containment", "%1 Options", containment()->title()), desktopMenu);
addContainmentActions(containmentMenu, event);
if (!containmentMenu->isEmpty()) {
int enabled = 0;
//count number of real actions
QListIterator<QAction *> actionsIt(containmentMenu->actions());
while (enabled < 3 && actionsIt.hasNext()) {
QAction *action = actionsIt.next();
if (action->isVisible() && !action->isSeparator()) {
++enabled;
}
}
desktopMenu->addSeparator();
if (enabled) {
//if there is only one, don't create a submenu
if (enabled < 2) {
@ -790,17 +790,17 @@ void DockView::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEve
}
}
}
if (containment()->immutability() == Plasma::Types::Mutable &&
(containment()->containmentType() != Plasma::Types::PanelContainment || containment()->isUserConfiguring())) {
QAction *closeApplet = applet->actions()->action(QStringLiteral("remove"));
//qDebug() << "checking for removal" << closeApplet;
if (closeApplet) {
if (!desktopMenu->isEmpty()) {
desktopMenu->addSeparator();
}
//qDebug() << "adding close action" << closeApplet->isEnabled() << closeApplet->isVisible();
desktopMenu->addAction(closeApplet);
}
@ -813,34 +813,34 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
if (!containment()) {
return;
}
if (containment()->corona()->immutability() != Plasma::Types::Mutable &&
!KAuthorized::authorizeAction(QStringLiteral("plasma/containment_actions"))) {
//qDebug() << "immutability";
return;
}
//this is what ContainmentPrivate::prepareContainmentActions was
const QString trigger = Plasma::ContainmentActions::eventToString(event);
//"RightButton;NoModifier"
Plasma::ContainmentActions *plugin = containment()->containmentActions().value(trigger);
if (!plugin) {
return;
}
if (plugin->containment() != containment()) {
plugin->setContainment(containment());
// now configure it
KConfigGroup cfg(containment()->corona()->config(), "ActionPlugins");
cfg = KConfigGroup(&cfg, QString::number(containment()->containmentType()));
KConfigGroup pluginConfig = KConfigGroup(&cfg, trigger);
plugin->restore(pluginConfig);
}
QList<QAction *> actions = plugin->contextualActions();
if (actions.isEmpty()) {
//it probably didn't bother implementing the function. give the user a chance to set
//a better plugin. note that if the user sets no-plugin this won't happen...
@ -852,7 +852,7 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
} else {
desktopMenu->addActions(actions);
}
return;
}

@ -103,7 +103,7 @@ public slots:
Q_INVOKABLE bool tasksPresent();
Q_INVOKABLE void closeApplication();
protected slots:
void showConfigurationInterface(Plasma::Applet *applet) override;
@ -111,7 +111,7 @@ protected:
bool event(QEvent *ev) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
signals:
void addInternalViewSplitter();
void removeInternalViewSplitter();
@ -130,7 +130,7 @@ signals:
private:
void initWindow();
void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event);
void addContainmentActions(QMenu *desktopMenu, QEvent *event);
void updatePosition();

Loading…
Cancel
Save