mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-11 13:18:13 +03:00
#15 Drag drop layout text
This commit is contained in:
parent
3ea099a54b
commit
b207950cc7
@ -46,6 +46,7 @@
|
|||||||
#include <QItemSelection>
|
#include <QItemSelection>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
// KDE
|
// KDE
|
||||||
#include <KArchive/KTar>
|
#include <KArchive/KTar>
|
||||||
@ -556,6 +557,29 @@ const Latte::Data::Layout Layouts::addLayoutForFile(QString file, QString layout
|
|||||||
return copied;
|
return copied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Latte::Data::Layout Layouts::addLayoutByText(QString rawLayoutText)
|
||||||
|
{
|
||||||
|
QTemporaryFile tempFile;
|
||||||
|
tempFile.open();
|
||||||
|
QTextStream stream(&tempFile);
|
||||||
|
stream << rawLayoutText;
|
||||||
|
stream.flush();
|
||||||
|
tempFile.close();
|
||||||
|
|
||||||
|
Latte::Data::Layout newLayout = addLayoutForFile(tempFile.fileName(),i18n("Dropped Raw Layout"));
|
||||||
|
|
||||||
|
int selectedRow = m_view->currentIndex().row();
|
||||||
|
QModelIndex tIndex = m_proxyModel->index(selectedRow, Model::Layouts::NAMECOLUMN);
|
||||||
|
m_view->edit(tIndex);
|
||||||
|
|
||||||
|
/**Window has to be activated explicitely since the window where the drag
|
||||||
|
* started would otherwise be the active window. By activating the window
|
||||||
|
the user can immediately change the name by simply typing.*/
|
||||||
|
m_handler->dialog()->activateWindow();
|
||||||
|
|
||||||
|
return newLayout;
|
||||||
|
}
|
||||||
|
|
||||||
void Layouts::copySelectedLayout()
|
void Layouts::copySelectedLayout()
|
||||||
{
|
{
|
||||||
int row = m_view->currentIndex().row();
|
int row = m_view->currentIndex().row();
|
||||||
|
@ -93,6 +93,7 @@ public:
|
|||||||
|
|
||||||
void copySelectedLayout();
|
void copySelectedLayout();
|
||||||
const Latte::Data::Layout addLayoutForFile(QString file, QString layoutName = QString(), bool newTempDirectory = true);
|
const Latte::Data::Layout addLayoutForFile(QString file, QString layoutName = QString(), bool newTempDirectory = true);
|
||||||
|
const Latte::Data::Layout addLayoutByText(QString rawLayoutText);
|
||||||
|
|
||||||
//! import layouts from Latte versions <= v0.7.x
|
//! import layouts from Latte versions <= v0.7.x
|
||||||
bool importLayoutsFromV1ConfigFile(QString file);
|
bool importLayoutsFromV1ConfigFile(QString file);
|
||||||
|
@ -685,6 +685,13 @@ void TabLayouts::on_layoutFilesDropped(const QStringList &paths)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabLayouts::on_rawLayoutDropped(const QString &rawLayout)
|
||||||
|
{
|
||||||
|
Latte::Data::Layout importedlayout = m_layoutsController->addLayoutByText(rawLayout);
|
||||||
|
showInlineMessage(i18nc("settings:layout imported successfully","Layout <b>%0</b> imported successfully...").arg(importedlayout.name),
|
||||||
|
KMessageWidget::Information);
|
||||||
|
}
|
||||||
|
|
||||||
bool TabLayouts::isCurrentTab() const
|
bool TabLayouts::isCurrentTab() const
|
||||||
{
|
{
|
||||||
return (m_layoutMenu->isEnabled() && (m_parentDialog->currentPage() == Dialog::LayoutPage));
|
return (m_layoutMenu->isEnabled() && (m_parentDialog->currentPage() == Dialog::LayoutPage));
|
||||||
@ -721,7 +728,7 @@ void TabLayouts::on_dragEnterEvent(QDragEnterEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
m_ui->layoutsView->dragEntered();
|
m_ui->layoutsView->dragEntered(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabLayouts::on_dragLeaveEvent(QDragLeaveEvent *event)
|
void TabLayouts::on_dragLeaveEvent(QDragLeaveEvent *event)
|
||||||
@ -738,7 +745,6 @@ void TabLayouts::on_dragMoveEvent(QDragMoveEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
m_ui->layoutsView->dragEntered();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabLayouts::on_dropEvent(QDropEvent *event)
|
void TabLayouts::on_dropEvent(QDropEvent *event)
|
||||||
@ -766,6 +772,15 @@ void TabLayouts::on_dropEvent(QDropEvent *event)
|
|||||||
on_layoutFilesDropped(paths);
|
on_layoutFilesDropped(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_ui->layoutsView->dragLeft();
|
||||||
|
} else if (event->mimeData()->hasText()){
|
||||||
|
if(!event->mimeData()->text().isEmpty()){
|
||||||
|
on_rawLayoutDropped(event->mimeData()->text());
|
||||||
|
} else if(!event->mimeData()->data("text/plain").isEmpty()) {
|
||||||
|
on_rawLayoutDropped(event->mimeData()->data("text/plain"));
|
||||||
|
} else {
|
||||||
|
qDebug() << "Data from drag could not be retrieved!";
|
||||||
|
}
|
||||||
m_ui->layoutsView->dragLeft();
|
m_ui->layoutsView->dragLeft();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ private slots:
|
|||||||
|
|
||||||
void on_currentPageChanged(int page);
|
void on_currentPageChanged(int page);
|
||||||
void on_layoutFilesDropped(const QStringList &paths);
|
void on_layoutFilesDropped(const QStringList &paths);
|
||||||
|
void on_rawLayoutDropped(const QString &rawLayout);
|
||||||
void updatePerLayoutButtonsState();
|
void updatePerLayoutButtonsState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
//! Qt
|
//! Qt
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
//! KDE
|
//! KDE
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
@ -70,12 +71,19 @@ void LayoutsTableView::paintEvent(QPaintEvent *event)
|
|||||||
QTableView::paintEvent(event);
|
QTableView::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutsTableView::dragEntered()
|
void LayoutsTableView::dragEntered(QDragEnterEvent *event)
|
||||||
{
|
{
|
||||||
m_overlayDropMessage->move(MARGIN, MARGIN);
|
m_overlayDropMessage->move(MARGIN, MARGIN);
|
||||||
m_overlayDropMessage->resize(width() - 2*MARGIN, height() - 2*MARGIN);
|
m_overlayDropMessage->resize(width() - 2*MARGIN, height() - 2*MARGIN);
|
||||||
|
|
||||||
m_overlayDropMessage->raise();
|
m_overlayDropMessage->raise();
|
||||||
|
if (event->mimeData()->hasUrls()) {
|
||||||
|
m_overlayDropMessage->setText(i18n("Drop layout files here..."));
|
||||||
|
} else if(event->mimeData()->hasText()) {
|
||||||
|
m_overlayDropMessage->setText(i18n("Drop raw layout text here..."));
|
||||||
|
} else {
|
||||||
|
m_overlayDropMessage->setText(i18n("Unsupported data!"));
|
||||||
|
}
|
||||||
m_overlayDropMessage->setVisible(true);
|
m_overlayDropMessage->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
|
||||||
namespace Latte {
|
namespace Latte {
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
@ -35,7 +36,7 @@ class LayoutsTableView : public QTableView
|
|||||||
public:
|
public:
|
||||||
LayoutsTableView(QWidget *parent = nullptr);
|
LayoutsTableView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
void dragEntered();
|
void dragEntered(QDragEnterEvent *event);
|
||||||
void dragLeft();
|
void dragLeft();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user