Commit a46910b3 authored by Alexander Semke's avatar Alexander Semke
Browse files

Improvements in ImageEntry(Dialog):

* double click to open the dialog for image settings
* place the "configure image" action at the very top of the context menu
* added clear button to the text field for the image path in the image settings dialog
* properly clear the context of the image preview on file name text changes
* minor code clean-up
parent 44a65254
Pipeline #63007 canceled with stage
......@@ -9,7 +9,6 @@
#include "worksheetview.h"
#include "lib/jupyterutils.h"
#include <QDebug>
#include <QDir>
#include <QMenu>
#include <QFileSystemWatcher>
......@@ -43,11 +42,13 @@ ImageEntry::ImageEntry(Worksheet* worksheet) : WorksheetEntry(worksheet)
void ImageEntry::populateMenu(QMenu* menu, QPointF pos)
{
menu->addAction(QIcon::fromTheme(QLatin1String("configure")), i18n("Configure Image"),
this, SLOT(startConfigDialog()));
menu->addSeparator();
WorksheetEntry::populateMenu(menu, pos);
auto* firstAction = menu->actions().at(0);
auto* action = new QAction(QIcon::fromTheme(QLatin1String("configure")), i18n("Configure Image"));
menu->insertAction(firstAction, action);
connect(action, &QAction::triggered, this, &ImageEntry::startConfigDialog);
menu->insertSeparator(firstAction);
}
bool ImageEntry::isEmpty()
......@@ -168,12 +169,14 @@ QDomElement ImageEntry::toXml(QDomDocument& doc, KZip* archive)
fileName.appendChild(fileNameText);
image.appendChild(fileName);
image.appendChild(path);
QDomElement display = doc.createElement(QLatin1String("Display"));
display.setAttribute(QLatin1String("width"), m_displaySize.width);
display.setAttribute(QLatin1String("widthUnit"), unitNames[m_displaySize.widthUnit]);
display.setAttribute(QLatin1String("height"), m_displaySize.height);
display.setAttribute(QLatin1String("heightUnit"), unitNames[m_displaySize.heightUnit]);
image.appendChild(display);
QDomElement print = doc.createElement(QLatin1String("Print"));
print.setAttribute(QLatin1String("useDisplaySize"), m_useDisplaySizeForPrinting);
print.setAttribute(QLatin1String("width"), m_printSize.width);
......@@ -255,7 +258,7 @@ void ImageEntry::updateEntry()
{
qreal oldHeight = height();
if (m_imagePath.isEmpty()) {
m_textItem->setPlainText(i18n("Right click here to insert image"));
m_textItem->setPlainText(i18n("Double click here to configure image settings"));
m_textItem->setVisible(true);
if (m_imageItem)
m_imageItem->setVisible(false);
......@@ -301,13 +304,11 @@ void ImageEntry::updateEntry()
if (m_imagePath.endsWith(QLatin1String(".eps"), Qt::CaseInsensitive))
size /= worksheet()->renderer()->scale();
m_imageItem->setSize(size);
qDebug() << size;
m_textItem->setVisible(false);
m_imageItem->setVisible(true);
}
}
qDebug() << oldHeight << height();
if (oldHeight != height())
recalculateSize();
}
......@@ -376,7 +377,6 @@ void ImageEntry::addActionsToBar(ActionBar* actionBar)
this, SLOT(startConfigDialog()));
}
void ImageEntry::layOutForWidth(qreal entry_zone_x, qreal w, bool force)
{
if (size().width() == w && m_textItem->pos().x() == entry_zone_x && !force)
......@@ -406,3 +406,8 @@ bool ImageEntry::wantFocus()
{
return false;
}
void ImageEntry::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*)
{
startConfigDialog();
}
......@@ -15,6 +15,7 @@ class Worksheet;
class ActionBar;
class WorksheetImageItem;
class QFileSystemWatcher;
class QGraphicsSceneMouseEvent;
class ImageEntry : public WorksheetEntry
{
......@@ -59,6 +60,8 @@ class ImageEntry : public WorksheetEntry
QString latexSizeString(const ImageSize& imgSize);
void addActionsToBar(ActionBar* actionBar) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
private:
QString m_imagePath;
QString m_fileName;
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>586</width>
<height>352</height>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
......@@ -17,7 +17,11 @@
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="KLineEdit" name="pathEdit"/>
<widget class="KLineEdit" name="pathEdit">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="openDialogButton">
......@@ -135,16 +139,16 @@
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KImageFilePreview</class>
<extends>QWidget</extends>
<header>kimagefilepreview.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KImageFilePreview</class>
<extends>QWidget</extends>
<header>kimagefilepreview.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>pathEdit</tabstop>
......
......@@ -24,10 +24,10 @@ ImageSettingsDialog::ImageSettingsDialog(QWidget* parent) : QDialog(parent)
setWindowIcon(QIcon::fromTheme(QLatin1String("viewimage")));
setAttribute(Qt::WA_DeleteOnClose);
QWidget* w = new QWidget(this);
auto* w = new QWidget(this);
m_ui.setupUi(w);
QVBoxLayout* vLayout = new QVBoxLayout(this);
auto* vLayout = new QVBoxLayout(this);
vLayout->setSpacing(0);
vLayout->setContentsMargins(0,0,0,0);
vLayout->addWidget(w);
......@@ -44,7 +44,7 @@ ImageSettingsDialog::ImageSettingsDialog(QWidget* parent) : QDialog(parent)
m_ui.printWidthCombo->addItems(m_unitNames);
m_ui.printHeightCombo->addItems(m_unitNames);
KUrlCompletion* completer = new KUrlCompletion(KUrlCompletion::FileCompletion);
auto* completer = new KUrlCompletion(KUrlCompletion::FileCompletion);
completer->setCompletionMode(KCompletion::CompletionMan);
m_ui.pathEdit->setCompletionObject(completer);
m_ui.pathEdit->setAutoDeleteCompletionObject( true );
......@@ -63,7 +63,7 @@ ImageSettingsDialog::ImageSettingsDialog(QWidget* parent) : QDialog(parent)
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &ImageSettingsDialog::close);
connect(m_ui.openDialogButton, &QPushButton::clicked, this, &ImageSettingsDialog::openDialog);
connect(m_ui.pathEdit, &KLineEdit::editingFinished, this, &ImageSettingsDialog::updatePreview);
connect(m_ui.pathEdit, &QLineEdit::textChanged, this, &ImageSettingsDialog::updatePreview);
connect(m_ui.displayWidthCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &ImageSettingsDialog::updateInputWidgets);
connect(m_ui.displayHeightCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &ImageSettingsDialog::updateInputWidgets);
......@@ -141,7 +141,7 @@ void ImageSettingsDialog::sendChanges()
void ImageSettingsDialog::openDialog()
{
KConfigGroup conf(KSharedConfig::openConfig(), QLatin1String("ImageSettingsDialog"));
QString dir = conf.readEntry(QLatin1String("LastImageDir"), QString());
const QString& dir = conf.readEntry(QLatin1String("LastImageDir"), QString());
QString formats;
for (const QByteArray& format : QImageReader::supportedImageFormats())
......@@ -168,7 +168,9 @@ void ImageSettingsDialog::openDialog()
void ImageSettingsDialog::updatePreview()
{
m_ui.imagePreview->showPreview(QUrl::fromLocalFile(m_ui.pathEdit->text()));
m_ui.imagePreview->clearPreview();
if (!m_ui.pathEdit->text().isEmpty())
m_ui.imagePreview->showPreview(QUrl::fromLocalFile(m_ui.pathEdit->text()));
}
void ImageSettingsDialog::updateInputWidgets()
......
......@@ -53,12 +53,11 @@ rendered(false)
void MarkdownEntry::populateMenu(QMenu* menu, QPointF pos)
{
WorksheetEntry::populateMenu(menu, pos);
QAction* firstAction;
if (!rendered)
{
WorksheetEntry::populateMenu(menu, pos);
firstAction = menu->actions().at(1); //insert the first action for Markdown after the "Evaluate" action
QAction* action = new QAction(QIcon::fromTheme(QLatin1String("viewimage")), i18n("Insert Image"));
connect(action, &QAction::triggered, this, &MarkdownEntry::insertImage);
......@@ -66,8 +65,6 @@ void MarkdownEntry::populateMenu(QMenu* menu, QPointF pos)
}
else
{
WorksheetEntry::populateMenu(menu, pos);
firstAction = menu->actions().at(0);
QAction* action = new QAction(QIcon::fromTheme(QLatin1String("edit-entry")), i18n("Enter Edit Mode"));
connect(action, &QAction::triggered, this, &MarkdownEntry::enterEditMode);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment