mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
end porting core part
todo: panels control, windows preview
This commit is contained in:
parent
35a5aa6a6c
commit
685c0390b4
@ -492,7 +492,7 @@ void AwesomeWidget::showUpdates(QString version)
|
|||||||
text += i18n("New version : %1", version) + QString("\n\n");
|
text += i18n("New version : %1", version) + QString("\n\n");
|
||||||
text += i18n("Click \"Ok\" to download");
|
text += i18n("Click \"Ok\" to download");
|
||||||
int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel);
|
int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
switch(select) {
|
switch (select) {
|
||||||
case QMessageBox::Ok:
|
case QMessageBox::Ok:
|
||||||
QDesktopServices::openUrl(QString(RELEASES) + version);
|
QDesktopServices::openUrl(QString(RELEASES) + version);
|
||||||
break;
|
break;
|
||||||
|
@ -75,7 +75,7 @@ QString GraphicalItem::getImage(const float value)
|
|||||||
view->resize(_width + 5.0, _height + 5.0);
|
view->resize(_width + 5.0, _height + 5.0);
|
||||||
|
|
||||||
// paint
|
// paint
|
||||||
switch(_type) {
|
switch (_type) {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
pen.setWidth(_width);
|
pen.setWidth(_width);
|
||||||
// inactive
|
// inactive
|
||||||
@ -190,7 +190,7 @@ QString GraphicalItem::getStrType()
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QString value;
|
QString value;
|
||||||
switch(_type) {
|
switch (_type) {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
value = QString("Vertical");
|
value = QString("Vertical");
|
||||||
break;
|
break;
|
||||||
|
@ -79,7 +79,7 @@ QString GraphicalItem::image(const float value)
|
|||||||
view->resize(m_width + 5.0, m_height + 5.0);
|
view->resize(m_width + 5.0, m_height + 5.0);
|
||||||
|
|
||||||
// paint
|
// paint
|
||||||
switch(m_type) {
|
switch (m_type) {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
pen.setWidth(m_width);
|
pen.setWidth(m_width);
|
||||||
// inactive
|
// inactive
|
||||||
@ -206,7 +206,7 @@ QString GraphicalItem::strType()
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QString value;
|
QString value;
|
||||||
switch(m_type) {
|
switch (m_type) {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
value = QString("Vertical");
|
value = QString("Vertical");
|
||||||
break;
|
break;
|
||||||
|
@ -188,7 +188,7 @@ QString DesktopPanel::panelLocationToStr(Plasma::Location loc)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Location" << loc;
|
if (debug) qDebug() << PDEBUG << ":" << "Location" << loc;
|
||||||
|
|
||||||
switch(loc) {
|
switch (loc) {
|
||||||
case Plasma::TopEdge:
|
case Plasma::TopEdge:
|
||||||
return i18n("Top Edge");
|
return i18n("Top Edge");
|
||||||
case Plasma::BottomEdge:
|
case Plasma::BottomEdge:
|
||||||
|
@ -14,9 +14,6 @@
|
|||||||
|
|
||||||
<group name="Advanced">
|
<group name="Advanced">
|
||||||
<!-- advanced -->
|
<!-- advanced -->
|
||||||
<entry name="tooltip" type="bool">
|
|
||||||
<default>true</default>
|
|
||||||
</entry>
|
|
||||||
<entry name="tooltipType" type="string">
|
<entry name="tooltipType" type="string">
|
||||||
<default>windows</default>
|
<default>windows</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -22,8 +22,14 @@
|
|||||||
#include <KWindowSystem/KWindowSystem>
|
#include <KWindowSystem/KWindowSystem>
|
||||||
#include <Plasma/Corona>
|
#include <Plasma/Corona>
|
||||||
|
|
||||||
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QListWidget>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QPixmap>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
|
||||||
#include <fontdialog/fontdialog.h>
|
#include <fontdialog/fontdialog.h>
|
||||||
@ -63,7 +69,6 @@ QStringList DPAdds::dictKeys()
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QStringList allKeys;
|
QStringList allKeys;
|
||||||
allKeys.append(QString("fullmark"));
|
|
||||||
allKeys.append(QString("mark"));
|
allKeys.append(QString("mark"));
|
||||||
allKeys.append(QString("name"));
|
allKeys.append(QString("name"));
|
||||||
allKeys.append(QString("number"));
|
allKeys.append(QString("number"));
|
||||||
@ -73,6 +78,57 @@ QStringList DPAdds::dictKeys()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString DPAdds::toolTipImage(const int desktop)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Desktop" << desktop;
|
||||||
|
|
||||||
|
// prepare
|
||||||
|
// clear
|
||||||
|
QGraphicsScene *toolTipScene = new QGraphicsScene();
|
||||||
|
QGraphicsView *toolTipView = new QGraphicsView(toolTipScene);
|
||||||
|
DesktopWindowsInfo info = getInfoByDesktop(desktop);
|
||||||
|
float margin = 5.0 * info.desktop.width() / 400.0;
|
||||||
|
toolTipView->resize(info.desktop.width() + 2.0 * margin, info.desktop.height() + 2.0 * margin);
|
||||||
|
toolTipScene->clear();
|
||||||
|
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||||
|
// borders
|
||||||
|
toolTipScene->addLine(0, 0, 0, info.desktop.height() + 2.0 * margin);
|
||||||
|
toolTipScene->addLine(0, info.desktop.height() + 2.0 * margin,
|
||||||
|
info.desktop.width() + 2.0 * margin, info.desktop.height() + 2.0 * margin);
|
||||||
|
toolTipScene->addLine(info.desktop.width() + 2.0 * margin, info.desktop.height() + 2.0 * margin,
|
||||||
|
info.desktop.width() + 2.0 * margin, 0);
|
||||||
|
toolTipScene->addLine(info.desktop.width() + 2.0 * margin, 0, 0, 0);
|
||||||
|
|
||||||
|
if (tooltipType == QString("contours")) {
|
||||||
|
QPen pen = QPen();
|
||||||
|
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||||
|
pen.setColor(QColor(tooltipColor));
|
||||||
|
for (int i=0; i<info.windows.count(); i++) {
|
||||||
|
toolTipScene->addLine(info.windows[i].left() + margin, info.windows[i].bottom() + margin,
|
||||||
|
info.windows[i].left() + margin, info.windows[i].top() + margin, pen);
|
||||||
|
toolTipScene->addLine(info.windows[i].left() + margin, info.windows[i].top() + margin,
|
||||||
|
info.windows[i].right() + margin, info.windows[i].top() + margin, pen);
|
||||||
|
toolTipScene->addLine(info.windows[i].right() + margin, info.windows[i].top() + margin,
|
||||||
|
info.windows[i].right() + margin, info.windows[i].bottom() + margin, pen);
|
||||||
|
toolTipScene->addLine(info.windows[i].right() + margin, info.windows[i].bottom() + margin,
|
||||||
|
info.windows[i].left() + margin, info.windows[i].bottom() + margin, pen);
|
||||||
|
}
|
||||||
|
} else if (tooltipType == QString("clean")) {
|
||||||
|
// toolTip.setWindowsToPreview(info.desktopId);
|
||||||
|
} else if (tooltipType == QString("windows")) {
|
||||||
|
// toolTip.setWindowsToPreview(info.winId);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap image = toolTipView->grab().scaledToWidth(tooltipWidth);
|
||||||
|
QByteArray byteArray;
|
||||||
|
QBuffer buffer(&byteArray);
|
||||||
|
image.save(&buffer, "PNG");
|
||||||
|
|
||||||
|
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString DPAdds::parsePattern(const QString pattern, const int desktop)
|
QString DPAdds::parsePattern(const QString pattern, const int desktop)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -89,6 +145,42 @@ QString DPAdds::parsePattern(const QString pattern, const int desktop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DPAdds::setMark(const QString newMark)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Mark" << newMark;
|
||||||
|
|
||||||
|
mark = newMark;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DPAdds::setPanelsToControl(const QString newPanels)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Panels" << newPanels;
|
||||||
|
|
||||||
|
panelsToControl.clear();
|
||||||
|
if (newPanels == QString("-1")) {
|
||||||
|
int count = getPanels().count();
|
||||||
|
for (int i=0; i<count; i++)
|
||||||
|
panelsToControl.append(i);
|
||||||
|
} else
|
||||||
|
for (int i=0; i<newPanels.split(QChar(',')).count(); i++)
|
||||||
|
panelsToControl.append(newPanels.split(QChar(','))[i].toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DPAdds::setToolTipData(const QMap< QString, QVariant > tooltipData)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Data" << tooltipData;
|
||||||
|
|
||||||
|
tooltipColor = tooltipData[QString("tooltipColor")].toString();
|
||||||
|
tooltipType = tooltipData[QString("tooltipType")].toString();
|
||||||
|
tooltipWidth = tooltipData[QString("tooltipWidth")].toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString DPAdds::valueByKey(const QString key, const int desktop)
|
QString DPAdds::valueByKey(const QString key, const int desktop)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -99,10 +191,8 @@ QString DPAdds::valueByKey(const QString key, const int desktop)
|
|||||||
currentMark = mark;
|
currentMark = mark;
|
||||||
else
|
else
|
||||||
currentMark = QString("");
|
currentMark = QString("");
|
||||||
if (key == QString("fullmark"))
|
if (key == QString("mark"))
|
||||||
return QString("%1").arg(currentMark, currentMark.count(), QLatin1Char(' '));
|
return QString("%1").arg(currentMark, currentMark.count(), QLatin1Char(' '));
|
||||||
else if (key == QString("mark"))
|
|
||||||
return currentMark;
|
|
||||||
else if (key == QString("name"))
|
else if (key == QString("name"))
|
||||||
return KWindowSystem::desktopName(desktop);
|
return KWindowSystem::desktopName(desktop);
|
||||||
else if (key == QString("number"))
|
else if (key == QString("number"))
|
||||||
@ -114,6 +204,56 @@ QString DPAdds::valueByKey(const QString key, const int desktop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString DPAdds::editPanelsToContol(const QString current)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
// paint
|
||||||
|
QDialog *dialog = new QDialog(0);
|
||||||
|
QListWidget *widget = new QListWidget(dialog);
|
||||||
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Close,
|
||||||
|
Qt::Vertical, dialog);
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(dialog);
|
||||||
|
layout->addWidget(widget);
|
||||||
|
layout->addWidget(buttons);
|
||||||
|
dialog->setLayout(layout);
|
||||||
|
connect(buttons, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||||
|
connect(buttons, SIGNAL(accepted()), dialog, SLOT(accept()));
|
||||||
|
|
||||||
|
// fill
|
||||||
|
QList<Plasma::Containment *> panels = getPanels();
|
||||||
|
for (int i=0; i<panels.count(); i++) {
|
||||||
|
QListWidgetItem *item = new QListWidgetItem(panelLocationToStr(panels[i]->location()), widget);
|
||||||
|
if ((current.split(QChar(',')).contains(QString::number(i))) ||
|
||||||
|
(current == QString("-1")))
|
||||||
|
item->setCheckState(Qt::Checked);
|
||||||
|
else
|
||||||
|
item->setCheckState(Qt::Unchecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
// exec
|
||||||
|
QString value;
|
||||||
|
QStringList indexes;
|
||||||
|
int ret = dialog->exec();
|
||||||
|
switch (ret) {
|
||||||
|
case QDialog::Accepted:
|
||||||
|
for (int i=0; i<widget->count(); i++)
|
||||||
|
if (widget->item(i)->checkState() == Qt::Checked)
|
||||||
|
indexes.append(QString::number(i));
|
||||||
|
if (indexes.count() == widget->count())
|
||||||
|
value = QString("-1");
|
||||||
|
else
|
||||||
|
value = indexes.join(QChar(','));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value = current;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString DPAdds::getAboutText(const QString type)
|
QString DPAdds::getAboutText(const QString type)
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -172,11 +312,11 @@ QMap<QString, QVariant> DPAdds::getFont(const QMap<QString, QVariant> defaultFon
|
|||||||
void DPAdds::changePanelsState()
|
void DPAdds::changePanelsState()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (panelsToControl == QString("-1")) return;
|
if (panelsToControl.isEmpty()) return;
|
||||||
|
|
||||||
QList<Plasma::Containment *> panels = getPanels();
|
QList<Plasma::Containment *> panels = getPanels();
|
||||||
// for (int i=0; i<panels.count(); i++) {
|
// for (int i=0; i<panels.count(); i++) {
|
||||||
// if (!panelsToControl.split(QChar(',')).contains(QString::number(i))) continue;
|
// if (!panelsToControl.contains(i)) continue;
|
||||||
// bool wasVisible = panels[i]->view()->isVisible();
|
// bool wasVisible = panels[i]->view()->isVisible();
|
||||||
// int winId = panels[i]->view()->winId();
|
// int winId = panels[i]->view()->winId();
|
||||||
// if (wasVisible) {
|
// if (wasVisible) {
|
||||||
@ -221,6 +361,34 @@ void DPAdds::changeDesktop(const int desktop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop)
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Desktop" << desktop;
|
||||||
|
|
||||||
|
|
||||||
|
DesktopWindowsInfo info;
|
||||||
|
info.desktop = KWindowSystem::workArea(desktop);
|
||||||
|
|
||||||
|
QList<WId> windows = KWindowSystem::windows();
|
||||||
|
for (int i=0; i<windows.count(); i++) {
|
||||||
|
KWindowInfo winInfo = KWindowInfo(windows[i],
|
||||||
|
NET::Property::WMDesktop | NET::Property::WMGeometry |
|
||||||
|
NET::Property::WMState | NET::Property::WMWindowType);
|
||||||
|
if (!winInfo.isOnDesktop(desktop)) continue;
|
||||||
|
if (winInfo.windowType(NET::WindowTypeMask::NormalMask) == NET::WindowType::Normal) {
|
||||||
|
if (winInfo.isMinimized()) continue;
|
||||||
|
info.windows.append(winInfo.geometry());
|
||||||
|
info.winId.append(windows[i]);
|
||||||
|
} else if (winInfo.windowType(NET::WindowTypeMask::DesktopMask) == NET::WindowType::Desktop) {
|
||||||
|
info.desktopId.append(windows[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<Plasma::Containment *> DPAdds::getPanels()
|
QList<Plasma::Containment *> DPAdds::getPanels()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -242,7 +410,7 @@ QString DPAdds::panelLocationToStr(Plasma::Types::Location location)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Location" << location;
|
if (debug) qDebug() << PDEBUG << ":" << "Location" << location;
|
||||||
|
|
||||||
switch(location) {
|
switch (location) {
|
||||||
case Plasma::Types::Location::TopEdge:
|
case Plasma::Types::Location::TopEdge:
|
||||||
return i18n("Top Edge");
|
return i18n("Top Edge");
|
||||||
case Plasma::Types::Location::BottomEdge:
|
case Plasma::Types::Location::BottomEdge:
|
||||||
|
@ -30,16 +30,28 @@ class DPAdds : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
QRect desktop;
|
||||||
|
QList<WId> desktopId;
|
||||||
|
QList<QRect> windows;
|
||||||
|
QList<WId> winId;
|
||||||
|
} DesktopWindowsInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DPAdds(QObject *parent = 0);
|
DPAdds(QObject *parent = 0);
|
||||||
~DPAdds();
|
~DPAdds();
|
||||||
|
|
||||||
Q_INVOKABLE bool isDebugEnabled();
|
Q_INVOKABLE bool isDebugEnabled();
|
||||||
Q_INVOKABLE QStringList dictKeys();
|
Q_INVOKABLE QStringList dictKeys();
|
||||||
|
Q_INVOKABLE QString toolTipImage(const int desktop);
|
||||||
Q_INVOKABLE QString parsePattern(const QString pattern, const int desktop);
|
Q_INVOKABLE QString parsePattern(const QString pattern, const int desktop);
|
||||||
// values
|
// values
|
||||||
|
Q_INVOKABLE void setMark(const QString newMark);
|
||||||
|
Q_INVOKABLE void setPanelsToControl(const QString newPanels);
|
||||||
|
Q_INVOKABLE void setToolTipData(const QMap<QString, QVariant> tooltipData);
|
||||||
Q_INVOKABLE QString valueByKey(const QString key, const int desktop);
|
Q_INVOKABLE QString valueByKey(const QString key, const int desktop);
|
||||||
// configuration slots
|
// configuration slots
|
||||||
|
Q_INVOKABLE QString editPanelsToContol(const QString current);
|
||||||
Q_INVOKABLE QString getAboutText(const QString type = "header");
|
Q_INVOKABLE QString getAboutText(const QString type = "header");
|
||||||
Q_INVOKABLE QMap<QString, QVariant> getFont(const QMap<QString, QVariant> defaultFont);
|
Q_INVOKABLE QMap<QString, QVariant> getFont(const QMap<QString, QVariant> defaultFont);
|
||||||
|
|
||||||
@ -55,12 +67,14 @@ private slots:
|
|||||||
void changeDesktop(const int desktop);
|
void changeDesktop(const int desktop);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DesktopWindowsInfo getInfoByDesktop(const int desktop);
|
||||||
QList<Plasma::Containment *> getPanels();
|
QList<Plasma::Containment *> getPanels();
|
||||||
QString panelLocationToStr(Plasma::Types::Location location);
|
QString panelLocationToStr(Plasma::Types::Location location);
|
||||||
// variables
|
// variables
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
int oldState;
|
int oldState, tooltipWidth;
|
||||||
QString mark, panelsToControl;
|
QString mark, tooltipColor, tooltipType;
|
||||||
|
QList<int> panelsToControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user