mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-07 08:58:17 +03:00
improve configuration window
--expose quit action --hide remove action when only one dock exists --udpate edges when a new dock is added --connect the destroyed event of containment in order to remove also the dockview --remove correctly the dockviews in the application exit
This commit is contained in:
parent
ba4837d47b
commit
cb0ed85dc2
@ -57,26 +57,18 @@ DockCorona::DockCorona(QObject *parent)
|
||||
connect(this, &Corona::containmentAdded, this, &DockCorona::addDock);
|
||||
|
||||
loadLayout();
|
||||
|
||||
/*QAction *addDock = actions()->add<QAction>(QStringLiteral("add dock"));
|
||||
connect(addDock, &QAction::triggered, this, &NowDockCorona::loadDefaultLayout);
|
||||
addDock->setText(i18n("Add New Dock"));
|
||||
addDock->setAutoRepeat(true);
|
||||
addDock->setStatusTip(tr("Adds a new dock in the environment"));
|
||||
addDock->setVisible(true);
|
||||
addDock->setEnabled(true);
|
||||
|
||||
addDock->setIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
|
||||
addDock->setData(Plasma::Types::ControlAction);
|
||||
addDock->setShortcut(QKeySequence(QStringLiteral("alt+d, l")));
|
||||
addDock->setShortcutContext(Qt::ApplicationShortcut);*/
|
||||
}
|
||||
|
||||
DockCorona::~DockCorona()
|
||||
{
|
||||
for (auto c : m_containments)
|
||||
c->deleteLater();
|
||||
|
||||
while (!containments().isEmpty()) {
|
||||
//deleting a containment will remove it from the list due to QObject::destroyed connect in Corona
|
||||
delete containments().first();
|
||||
}
|
||||
|
||||
qDeleteAll(m_dockViews);
|
||||
m_dockViews.clear();
|
||||
|
||||
qDebug() << "deleted" << this;
|
||||
}
|
||||
|
||||
@ -136,6 +128,16 @@ int DockCorona::primaryScreenId() const
|
||||
return id;
|
||||
}
|
||||
|
||||
int DockCorona::numDocks()
|
||||
{
|
||||
return m_dockViews.size();
|
||||
}
|
||||
|
||||
void DockCorona::closeApplication()
|
||||
{
|
||||
qGuiApp->quit();
|
||||
}
|
||||
|
||||
QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
|
||||
{
|
||||
using Plasma::Types;
|
||||
@ -145,7 +147,7 @@ QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
|
||||
//when screen=-1 is passed then the primaryScreenid is used
|
||||
int fixedScreen = (screen == -1) ? primaryScreenId() : screen;
|
||||
|
||||
for (const DockView *cont : m_containments) {
|
||||
for (const DockView *cont : m_dockViews) {
|
||||
if (cont && cont->containment()->screen() == fixedScreen)
|
||||
edges.removeOne(cont->location());
|
||||
}
|
||||
@ -155,7 +157,7 @@ QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
|
||||
|
||||
int DockCorona::screenForContainment(const Plasma::Containment *containment) const
|
||||
{
|
||||
for (auto *view : m_containments) {
|
||||
for (auto *view : m_dockViews) {
|
||||
if (view && view->containment() && view->containment()->id() == containment->id())
|
||||
if (view->screen())
|
||||
return qGuiApp->screens().indexOf(view->screen());
|
||||
@ -179,7 +181,7 @@ void DockCorona::addDock(Plasma::Containment *containment)
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (DockView *dock, m_containments) {
|
||||
foreach (DockView *dock, m_dockViews) {
|
||||
if (dock->containment() == containment) {
|
||||
return;
|
||||
}
|
||||
@ -190,9 +192,20 @@ void DockCorona::addDock(Plasma::Containment *containment)
|
||||
auto dockView = new DockView(this);
|
||||
dockView->init();
|
||||
dockView->setContainment(containment);
|
||||
connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed);
|
||||
|
||||
dockView->show();
|
||||
|
||||
m_containments.push_back(dockView);
|
||||
|
||||
m_dockViews[containment] = dockView;
|
||||
|
||||
emit containmentsNoChanged();
|
||||
}
|
||||
|
||||
void DockCorona::dockContainmentDestroyed(QObject *cont)
|
||||
{
|
||||
auto view = m_dockViews.take(static_cast<Plasma::Containment *>(cont));
|
||||
view->deleteLater();
|
||||
emit containmentsNoChanged();
|
||||
}
|
||||
|
||||
void DockCorona::loadDefaultLayout()
|
||||
|
@ -48,20 +48,26 @@ public:
|
||||
QList<Plasma::Types::Location> freeEdges(int screen) const;
|
||||
|
||||
int screenForContainment(const Plasma::Containment *containment) const override;
|
||||
int numDocks();
|
||||
|
||||
void addDock(Plasma::Containment *containment);
|
||||
|
||||
void closeApplication();
|
||||
|
||||
public slots:
|
||||
void loadDefaultLayout() override;
|
||||
void dockContainmentDestroyed(QObject *cont);
|
||||
|
||||
signals:
|
||||
void configurationShown(PlasmaQuick::ConfigView *configView);
|
||||
void containmentsNoChanged();
|
||||
|
||||
private:
|
||||
void qmlRegisterTypes() const;
|
||||
int primaryScreenId() const;
|
||||
|
||||
std::vector<DockView *> m_containments;
|
||||
//std::vector<DockView *> m_containments;
|
||||
QHash<const Plasma::Containment *, DockView *> m_dockViews;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ namespace Latte {
|
||||
|
||||
DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
|
||||
: PlasmaQuick::ContainmentView(corona),
|
||||
m_contextMenu(0)
|
||||
m_contextMenu(0),
|
||||
m_docksCount(0)
|
||||
{
|
||||
setVisible(false);
|
||||
setTitle(corona->kPackage().metadata().name());
|
||||
@ -81,6 +82,10 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
|
||||
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
|
||||
@ -89,6 +94,12 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen)
|
||||
//containment()->actions()->removeAction(addWidgetsAction);
|
||||
|
||||
}, Qt::DirectConnection);
|
||||
|
||||
DockCorona *dcorona = qobject_cast<DockCorona *>(this->corona());
|
||||
|
||||
if (dcorona) {
|
||||
connect(dcorona, &DockCorona::containmentsNoChanged, this, &DockView::updateDocksCount);
|
||||
}
|
||||
}
|
||||
|
||||
DockView::~DockView()
|
||||
@ -135,6 +146,8 @@ void DockView::init()
|
||||
connect(&m_lockGeometry, &QTimer::timeout, [&]() {
|
||||
updateDockPosition();
|
||||
});
|
||||
|
||||
updateDocksCount();
|
||||
|
||||
qDebug() << "SOURCE:" << source();
|
||||
|
||||
@ -373,6 +386,28 @@ bool DockView::compositing() const
|
||||
return WindowSystem::self().compositingActive();
|
||||
}
|
||||
|
||||
int DockView::docksCount() const
|
||||
{
|
||||
return m_docksCount;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/*Candil::VisibilityManager *DockView::visibility()
|
||||
{
|
||||
return m_visibility.data();
|
||||
@ -526,6 +561,17 @@ QList<int> DockView::freeEdges() const
|
||||
return edgesInt;
|
||||
}
|
||||
|
||||
void DockView::closeApplication()
|
||||
{
|
||||
DockCorona *corona = qobject_cast<DockCorona *>(this->corona());
|
||||
|
||||
if (corona) {
|
||||
m_configView->hide();
|
||||
corona->closeApplication();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DockView::saveConfig()
|
||||
{
|
||||
if (!containment())
|
||||
|
@ -46,6 +46,7 @@ class DockView : public PlasmaQuick::ContainmentView {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(bool compositing READ compositing NOTIFY compositingChanged)
|
||||
Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged)
|
||||
Q_PROPERTY(int height READ height NOTIFY heightChanged)
|
||||
Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
|
||||
Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength NOTIFY maxLengthChanged)
|
||||
@ -84,6 +85,8 @@ public:
|
||||
void setOffset(int offset);
|
||||
|
||||
void updateOffset();
|
||||
|
||||
int docksCount() const;
|
||||
|
||||
VisibilityManager *visibility();
|
||||
|
||||
@ -109,6 +112,8 @@ public slots:
|
||||
Q_INVOKABLE void removeDock();
|
||||
Q_INVOKABLE void setLocalDockGeometry(const QRect &geometry);
|
||||
Q_INVOKABLE bool tasksPresent();
|
||||
Q_INVOKABLE void closeApplication();
|
||||
|
||||
void resizeWindow();
|
||||
void restoreConfig();
|
||||
void saveConfig();
|
||||
@ -130,6 +135,7 @@ signals:
|
||||
void compositingChanged();
|
||||
void heightChanged();
|
||||
void lengthChanged();
|
||||
void docksCountChanged();
|
||||
void localDockGeometryChanged();
|
||||
void maskAreaChanged();
|
||||
void maxLengthChanged();
|
||||
@ -145,10 +151,12 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void menuAboutToHide();
|
||||
void updateDocksCount();
|
||||
|
||||
private:
|
||||
bool m_secondInitPass;
|
||||
|
||||
int m_docksCount;
|
||||
int m_offset{0};
|
||||
int m_maxThickness{24};
|
||||
int m_length{0};
|
||||
|
@ -311,7 +311,7 @@ Item {
|
||||
onAnyTaskDemandsAttentionChanged: {
|
||||
if (anyTaskDemandsAttention){
|
||||
plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus;
|
||||
attentionTimerComponent.createObject(panel);
|
||||
attentionTimerComponent.createObject(root);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,13 @@ PlasmaComponents.Page{
|
||||
|
||||
onDockLocationChanged: updateDockLocationVisual();
|
||||
|
||||
property int docksCount: dock.docksCount
|
||||
|
||||
onDocksCountChanged: {
|
||||
lockReservedEdges();
|
||||
updateDockLocationVisual();
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
lockReservedEdges();
|
||||
updateDockLocationVisual();
|
||||
|
@ -188,12 +188,15 @@ PlasmaCore.FrameSvgItem {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: windowSpace
|
||||
|
||||
spacing: windowSpace
|
||||
spacing: 2
|
||||
width: parent.width - 2*windowSpace
|
||||
|
||||
PlasmaComponents.Button{
|
||||
enabled: true
|
||||
text: i18n("Add New Dock")
|
||||
text: i18n("Add")
|
||||
iconSource: "list-add"
|
||||
|
||||
width: parent.width/4 - 2
|
||||
|
||||
onClicked: dock.addNewDock();
|
||||
|
||||
@ -206,10 +209,27 @@ PlasmaCore.FrameSvgItem {
|
||||
}
|
||||
PlasmaComponents.Button{
|
||||
enabled: true
|
||||
text: i18n("Remove Dock")
|
||||
text: i18n("Remove")
|
||||
iconSource: "edit-delete"
|
||||
width: parent.width/4 - 2
|
||||
opacity: dock.docksCount > 1 ? 1 : 0
|
||||
|
||||
onClicked: dock.removeDock();
|
||||
}
|
||||
|
||||
Item{
|
||||
width: parent.width/4 - 2
|
||||
height: 1
|
||||
}
|
||||
|
||||
PlasmaComponents.Button{
|
||||
enabled: true
|
||||
text: i18n("Quit")
|
||||
iconSource: "window-close"
|
||||
width: parent.width/4 - 2
|
||||
|
||||
onClicked: dock.closeApplication();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user