improve auto sync geometry, and cleaning code unused

pull/1/head
Johan Smith Agudelo Rodriguez
parent 417f6f9e38
commit 2cb031ee50

@ -37,9 +37,9 @@ namespace Latte {
DockConfigView::DockConfigView(Plasma::Containment *containment, DockView *dockView, QWindow *parent) DockConfigView::DockConfigView(Plasma::Containment *containment, DockView *dockView, QWindow *parent)
: PlasmaQuick::ConfigView(containment, parent), : PlasmaQuick::ConfigView(containment, parent),
m_blockFocusLost(false),
m_containment(containment), m_containment(containment),
m_dockView(dockView), m_dockView(dockView)
m_blockFocusLost(false)
{ {
connections << connect(dockView, &QObject::destroyed, this, &QObject::deleteLater); connections << connect(dockView, &QObject::destroyed, this, &QObject::deleteLater);
@ -138,7 +138,6 @@ void DockConfigView::syncGeometry()
default: default:
qWarning() << "no sync geometry, wrong formFactor"; qWarning() << "no sync geometry, wrong formFactor";
//<< qEnumToStr(m_containment->formFactor());
break; break;
} }
} }
@ -199,7 +198,6 @@ void DockConfigView::showEvent(QShowEvent *ev)
void DockConfigView::hideEvent(QHideEvent *ev) void DockConfigView::hideEvent(QHideEvent *ev)
{ {
if (m_containment && m_dockView) { if (m_containment && m_dockView) {
m_dockView->saveConfig();
m_containment->setUserConfiguring(false); m_containment->setUserConfiguring(false);
} }

@ -45,8 +45,8 @@ namespace Latte {
DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
: PlasmaQuick::ContainmentView(corona), : PlasmaQuick::ContainmentView(corona),
m_contextMenu(0), m_docksCount(0),
m_docksCount(0) m_contextMenu(nullptr)
{ {
setVisible(false); setVisible(false);
setTitle(corona->kPackage().metadata().name()); setTitle(corona->kPackage().metadata().name());
@ -55,12 +55,14 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
setResizeMode(QuickViewSharedEngine::SizeRootObjectToView); setResizeMode(QuickViewSharedEngine::SizeRootObjectToView);
setClearBeforeRendering(true); setClearBeforeRendering(true);
timerSyncGeometry.setSingleShot(true);
timerSyncGeometry.setInterval(400);
if (targetScreen) if (targetScreen)
adaptToScreen(targetScreen); adaptToScreen(targetScreen);
else else
adaptToScreen(qGuiApp->primaryScreen()); adaptToScreen(qGuiApp->primaryScreen());
connect(this, &DockView::containmentChanged connect(this, &DockView::containmentChanged
, this, [&]() { , this, [&]() {
if (!containment()) if (!containment())
@ -97,58 +99,43 @@ DockView::~DockView()
{ {
qDebug() << "dock view deleting..."; qDebug() << "dock view deleting...";
foreach (auto var, connections) { foreach (auto &var, connections) {
QObject::disconnect(var); QObject::disconnect(var);
} }
qDebug() << "dock view connections deleted..."; qDebug() << "dock view connections deleted...";
if (m_visibility) { if (m_visibility) {
delete m_visibility; m_visibility.clear();
} }
} }
void DockView::init() void DockView::init()
{ {
connect(this, &DockView::screenChanged connect(this, &DockView::screenChanged, this, &DockView::adaptToScreen, Qt::QueuedConnection);
, this, &DockView::adaptToScreen connect(this, &DockView::screenGeometryChanged, this, &DockView::syncGeometry, Qt::QueuedConnection);
, Qt::QueuedConnection); connect(this, &QQuickWindow::widthChanged, this, &DockView::widthChanged);
connect(this, &QQuickWindow::heightChanged, this, &DockView::heightChanged);
connect(this, &DockView::locationChanged, [&]() {
//! avoid glitches
syncGeometry();
});
connect(this, &DockView::screenGeometryChanged
, this, &DockView::syncGeometry
, Qt::QueuedConnection);
connect(this, SIGNAL(widthChanged(int)), this, SIGNAL(widthChanged())); connect(this, &DockView::locationChanged, this, &DockView::syncGeometry);
connect(this, SIGNAL(heightChanged(int)), this, SIGNAL(heightChanged())); 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::localDockGeometryChanged, this, &DockView::updateAbsDockGeometry);
connect(&timerSyncGeometry, &QTimer::timeout, this, &DockView::updatePosition);
rootContext()->setContextProperty(QStringLiteral("dock"), this);
engine()->rootContext()->setContextObject(new KLocalizedContext(this)); engine()->rootContext()->setContextObject(new KLocalizedContext(this));
rootContext()->setContextProperty(QStringLiteral("dock"), this);
// engine()->rootContext()->setContextProperty(QStringLiteral("dock"), this);
setSource(corona()->kPackage().filePath("lattedockui")); setSource(corona()->kPackage().filePath("lattedockui"));
connect(this, SIGNAL(xChanged(int)), this, SLOT(syncGeometry())); setVisible(true);
connect(this, SIGNAL(yChanged(int)), this, SLOT(syncGeometry()));
connect(this, SIGNAL(localDockGeometryChanged()), this, SLOT(updateAbsDockGeometry()));
connect(this, SIGNAL(xChanged(int)), this, SLOT(updateAbsDockGeometry()));
connect(this, SIGNAL(yChanged(int)), this, SLOT(updateAbsDockGeometry()));
updateDocksCount(); updateDocksCount();
syncGeometry(); syncGeometry();
setVisible(true);
qDebug() << "SOURCE:" << source(); qDebug() << "SOURCE:" << source();
} }
//!BEGIN SLOTS
void DockView::adaptToScreen(QScreen *screen) void DockView::adaptToScreen(QScreen *screen)
{ {
setScreen(screen); setScreen(screen);
@ -158,9 +145,6 @@ void DockView::adaptToScreen(QScreen *screen)
else else
m_maxLength = screen->size().width(); m_maxLength = screen->size().width();
// KWindowSystem::setOnAllDesktops(winId(), true);
// KWindowSystem::setType(winId(), NET::Dock);
if (containment()) if (containment())
containment()->reactToScreenChange(); containment()->reactToScreenChange();
@ -256,8 +240,6 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet)
void DockView::resizeWindow() void DockView::resizeWindow()
{ {
setVisible(true);
QSize screenSize = screen()->size(); QSize screenSize = screen()->size();
if (formFactor() == Plasma::Types::Vertical) { if (formFactor() == Plasma::Types::Vertical) {
@ -290,11 +272,14 @@ void DockView::setLocalDockGeometry(const QRect &geometry)
void DockView::updateAbsDockGeometry() void DockView::updateAbsDockGeometry()
{ {
if (!m_visibility)
return;
QRect absoluteGeometry {x() + m_localDockGeometry.x(), y() + m_localDockGeometry.y(), m_localDockGeometry.width(), m_localDockGeometry.height()}; QRect absoluteGeometry {x() + m_localDockGeometry.x(), y() + m_localDockGeometry.y(), m_localDockGeometry.width(), m_localDockGeometry.height()};
m_visibility->updateDockGeometry(absoluteGeometry); m_visibility->updateDockGeometry(absoluteGeometry);
} }
void DockView::syncGeometryImmediately() void DockView::updatePosition()
{ {
if (!containment()) if (!containment())
return; return;
@ -304,31 +289,26 @@ void DockView::syncGeometryImmediately()
qDebug() << "current dock geometry: " << geometry(); qDebug() << "current dock geometry: " << geometry();
// containment()->setFormFactor(Plasma::Types::Horizontal);
position = {0, 0}; position = {0, 0};
m_maxLength = screenGeometry.width(); m_maxLength = screenGeometry.width();
switch (location()) { switch (location()) {
case Plasma::Types::TopEdge: case Plasma::Types::TopEdge:
containment()->setFormFactor(Plasma::Types::Horizontal);
position = {screenGeometry.x(), screenGeometry.y()}; position = {screenGeometry.x(), screenGeometry.y()};
m_maxLength = screenGeometry.width(); m_maxLength = screenGeometry.width();
break; break;
case Plasma::Types::BottomEdge: case Plasma::Types::BottomEdge:
containment()->setFormFactor(Plasma::Types::Horizontal);
position = {screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - height()}; position = {screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - height()};
m_maxLength = screenGeometry.width(); m_maxLength = screenGeometry.width();
break; break;
case Plasma::Types::RightEdge: case Plasma::Types::RightEdge:
containment()->setFormFactor(Plasma::Types::Vertical);
position = {screenGeometry.x() + screenGeometry.width() - width(), screenGeometry.y()}; position = {screenGeometry.x() + screenGeometry.width() - width(), screenGeometry.y()};
m_maxLength = screenGeometry.height(); m_maxLength = screenGeometry.height();
break; break;
case Plasma::Types::LeftEdge: case Plasma::Types::LeftEdge:
containment()->setFormFactor(Plasma::Types::Vertical);
position = {screenGeometry.x(), screenGeometry.y()}; position = {screenGeometry.x(), screenGeometry.y()};
m_maxLength = screenGeometry.height(); m_maxLength = screenGeometry.height();
break; break;
@ -339,24 +319,22 @@ void DockView::syncGeometryImmediately()
} }
emit maxLengthChanged(); emit maxLengthChanged();
setX(position.x()); setPosition(position);
setY(position.y());
resizeWindow();
//setPosition(position);
qDebug() << "dock position:" << position; qDebug() << "dock position:" << position;
} }
inline void DockView::syncGeometry() inline void DockView::syncGeometry()
{ {
syncGeometryImmediately(); updateFormFactor();
resizeWindow();
QTimer::singleShot(400, this, &DockView::syncGeometryImmediately); updatePosition();
updateAbsDockGeometry();
} }
int DockView::currentThickness() const int DockView::currentThickness() const
{ {
if (containment()->formFactor() == Plasma::Types::Vertical) { if (formFactor() == Plasma::Types::Vertical) {
return m_maskArea.isNull() ? width() : m_maskArea.width(); return m_maskArea.isNull() ? width() : m_maskArea.width();
} else { } else {
return m_maskArea.isNull() ? height() : m_maskArea.height(); return m_maskArea.isNull() ? height() : m_maskArea.height();
@ -385,10 +363,27 @@ void DockView::updateDocksCount()
} }
} }
/*Candil::VisibilityManager *DockView::visibility() void DockView::updateFormFactor()
{ {
return m_visibility.data(); 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();
}
}
int DockView::maxThickness() const int DockView::maxThickness() const
{ {
@ -446,9 +441,8 @@ QRect DockView::maskArea() const
void DockView::setMaskArea(QRect area) void DockView::setMaskArea(QRect area)
{ {
if (m_maskArea == area) { if (m_maskArea == area)
return; return;
}
m_maskArea = area; m_maskArea = area;
@ -502,52 +496,13 @@ void DockView::closeApplication()
if (corona) { if (corona) {
//m_configView->hide(); //m_configView->hide();
if (m_configView) { if (m_configView)
m_configView->deleteLater(); m_configView->deleteLater();
}
corona->closeApplication(); corona->closeApplication();
} }
} }
void DockView::saveConfig()
{
if (!containment())
return;
const auto writeEntry = [&](const char *entry, const QVariant & value) {
containment()->config().writeEntry(entry, value);
};
//! convert offset to percent, range [-1,1] 0 is Centered
//! offsetPercent = offset * 2 / (maxLength - length)
// const float offsetPercent = m_offset * 2.0f / (m_maxLength - m_length);
// writeEntry("offset", offsetPercent);
// writeEntry("iconSize", m_iconSize);
// writeEntry("zoomFactor", m_zoomFactor);
// writeEntry("alignment", static_cast<int>(m_alignment));
}
void DockView::restoreConfig()
{
if (!containment())
return;
const auto readEntry = [&](const char *entry, QVariant defaultValue) -> QVariant {
return containment()->config().readEntry(entry, defaultValue);
};
//! convert offset-percent to pixels
//! offset = offsetPercent * (maxLength - length) / 2
// const float offsetPercent {readEntry("offset", 0).toFloat()};
// const int offset {static_cast<int>(offsetPercent * (m_maxLength - m_length) / 2)};
// setOffset(offset);
// setIconSize(readEntry("iconSize", 32).toInt());
// setZoomFactor(readEntry("zoomFactor", 1.0).toFloat());
// setAlignment(static_cast<Dock::Alignment>(readEntry("alignment", Dock::Center).toInt()));
}
QVariantList DockView::containmentActions() QVariantList DockView::containmentActions()
{ {
QVariantList actions; QVariantList actions;
@ -582,7 +537,8 @@ QVariantList DockView::containmentActions()
return actions; return actions;
} }
//!END SLOTS
//!BEGIN overriding context menus behavior //!BEGIN overriding context menus behavior
void DockView::addAppletItem(QObject *item) void DockView::addAppletItem(QObject *item)
{ {

Loading…
Cancel
Save