2024-11-18 09:33:05 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
2024-10-04 16:36:16 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtInstanceEntry.hxx>
|
2024-10-24 12:27:27 +02:00
|
|
|
#include <QtInstanceEntry.moc>
|
2024-10-04 16:36:16 +02:00
|
|
|
|
2024-10-24 00:19:56 +02:00
|
|
|
#include <vcl/qt/QtUtils.hxx>
|
|
|
|
|
2024-11-04 16:49:42 +01:00
|
|
|
#include <QtGui/QIcon>
|
|
|
|
|
2024-10-04 16:36:16 +02:00
|
|
|
QtInstanceEntry::QtInstanceEntry(QLineEdit* pLineEdit)
|
|
|
|
: QtInstanceWidget(pLineEdit)
|
|
|
|
, m_pLineEdit(pLineEdit)
|
|
|
|
{
|
|
|
|
assert(m_pLineEdit);
|
2024-10-24 12:27:27 +02:00
|
|
|
|
|
|
|
QObject::connect(m_pLineEdit, &QLineEdit::cursorPositionChanged, this,
|
|
|
|
[&] { signal_cursor_position(); });
|
tdf#130857 qt weld: Notify about spinbox combined value+text change
While QtInstanceEntry generally takes care of handling signals
for the spinbox's QLineEdit, this doesn't work when the value
is changed as a result of setting a new spinbox value (e.g.
by using the spinbox buttons), as the QLineEdit signals are blocked
then, see QAbstractSpinBoxPrivate::updateEdit in qtbase [1].
Therefore, connect the QDoubleSpinBox::textChanged signal
to the slot that calls signal_changed() instead to ensure
it gets called nonetheless, and disconnect from the other signal.
While at it, also add a SolarMutexGuard when calling the
signal.
This fixes the issue noticed with the "Go to Page"
dialog mentioned in previous commit
Change-Id: I1f24cf3925e945ae78a9f1646535e08736cd8786
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Wed Nov 27 23:53:58 2024 +0100
tdf#130857 qt weld: Support "Go to Page" dialog
as:
> One issue seen with the dialog is that by using the
> up arrow of the spinbox to increase the value, it
> is currently possible to increase the value
> beyond the maximum value (last page number),
> while this is not the case when typing a number
> into the box manually.
>
> This is because the GotoPageDlg::PageModifiedHdl
> handler currently only gets called for the
> latter case, not the former one, despite
>
> Change-Id: Ie19bc852f4ceed0fa79565302975376db7126ea4
> Author: Michael Weghorn <m.weghorn@posteo.de>
> Date: Wed Nov 27 22:53:55 2024 +0100
>
> tdf#130857 qt weld: Also notify about programmatic text changes
>
> and will be addressed in a separate commit.
[1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qabstractspinbox.cpp?id=ced47a590aeb85953a16eaf362887f14c2815c45#n1790
Change-Id: Ifba9a0877442f9e84f0103d8aab202ae3583c5cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177451
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-28 00:30:10 +01:00
|
|
|
QObject::connect(m_pLineEdit, &QLineEdit::textChanged, this,
|
|
|
|
&QtInstanceEntry::handleTextChanged);
|
2024-10-04 16:36:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_text(const OUString& rText)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->setText(toQString(rText)); });
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString QtInstanceEntry::get_text() const
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
OUString sText;
|
|
|
|
GetQtInstance().RunInMainThread([&] { sText = toOUString(m_pLineEdit->text()); });
|
|
|
|
return sText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_width_chars(int) { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
int QtInstanceEntry::get_width_chars() const
|
|
|
|
{
|
|
|
|
assert(false && "Not implemented yet");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_max_length(int nChars)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->setMaxLength(nChars); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::select_region(int nStartPos, int nEndPos)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
|
|
|
|
GetQtInstance().RunInMainThread([&] {
|
|
|
|
if (nEndPos == -1)
|
|
|
|
nEndPos = m_pLineEdit->text().length();
|
|
|
|
|
|
|
|
const int nLength = nEndPos - nStartPos;
|
|
|
|
m_pLineEdit->setSelection(nStartPos, nLength);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QtInstanceEntry::get_selection_bounds(int& rStartPos, int& rEndPos)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
|
|
|
|
bool bHasSelection = false;
|
|
|
|
GetQtInstance().RunInMainThread([&] {
|
|
|
|
bHasSelection = m_pLineEdit->hasSelectedText();
|
|
|
|
rStartPos = m_pLineEdit->selectionStart();
|
|
|
|
rEndPos = m_pLineEdit->selectionEnd();
|
|
|
|
});
|
|
|
|
|
|
|
|
return bHasSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::replace_selection(const OUString& rText)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->insert(toQString(rText)); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_position(int nCursorPos)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
2024-11-27 23:26:04 +01:00
|
|
|
if (nCursorPos == -1)
|
|
|
|
nCursorPos = m_pLineEdit->text().length();
|
|
|
|
|
2024-10-04 16:36:16 +02:00
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->setCursorPosition(nCursorPos); });
|
|
|
|
}
|
|
|
|
|
|
|
|
int QtInstanceEntry::get_position() const
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
int nCursorPos = 0;
|
|
|
|
GetQtInstance().RunInMainThread([&] { nCursorPos = m_pLineEdit->cursorPosition(); });
|
|
|
|
|
|
|
|
return nCursorPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_editable(bool bEditable)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->setReadOnly(!bEditable); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QtInstanceEntry::get_editable() const
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
bool bEditable = false;
|
|
|
|
GetQtInstance().RunInMainThread([&] { bEditable = !m_pLineEdit->isReadOnly(); });
|
|
|
|
|
|
|
|
return bEditable;
|
|
|
|
}
|
|
|
|
|
2024-12-04 22:09:12 +01:00
|
|
|
void QtInstanceEntry::setMessageType(QLineEdit& rLineEdit, weld::EntryMessageType eType)
|
2024-10-04 16:36:16 +02:00
|
|
|
{
|
2024-11-04 16:49:42 +01:00
|
|
|
SolarMutexGuard g;
|
|
|
|
|
|
|
|
GetQtInstance().RunInMainThread([&] {
|
2024-12-04 22:09:12 +01:00
|
|
|
for (QAction* pAction : rLineEdit.actions())
|
|
|
|
rLineEdit.removeAction(pAction);
|
2024-11-04 16:49:42 +01:00
|
|
|
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case weld::EntryMessageType::Normal:
|
|
|
|
// don't do anything special
|
|
|
|
return;
|
|
|
|
case weld::EntryMessageType::Warning:
|
2024-12-04 22:09:12 +01:00
|
|
|
rLineEdit.addAction(QIcon::fromTheme("dialog-warning"),
|
|
|
|
QLineEdit::TrailingPosition);
|
2024-11-04 16:49:42 +01:00
|
|
|
return;
|
|
|
|
case weld::EntryMessageType::Error:
|
2024-12-04 22:09:12 +01:00
|
|
|
rLineEdit.addAction(QIcon::fromTheme("dialog-error"), QLineEdit::TrailingPosition);
|
2024-11-04 16:49:42 +01:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
assert(false && "Unknown EntryMessageType");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2024-10-04 16:36:16 +02:00
|
|
|
}
|
|
|
|
|
2024-12-04 22:09:12 +01:00
|
|
|
void QtInstanceEntry::set_message_type(weld::EntryMessageType eType)
|
|
|
|
{
|
|
|
|
setMessageType(*m_pLineEdit, eType);
|
|
|
|
}
|
|
|
|
|
2024-10-04 16:36:16 +02:00
|
|
|
void QtInstanceEntry::set_placeholder_text(const OUString& rText)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
GetQtInstance().RunInMainThread([&] { m_pLineEdit->setPlaceholderText(toQString(rText)); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_overwrite_mode(bool) { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
bool QtInstanceEntry::get_overwrite_mode() const
|
|
|
|
{
|
|
|
|
assert(false && "Not implemented yet");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_font(const vcl::Font&) { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_font_color(const Color&) { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
void QtInstanceEntry::cut_clipboard() { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
void QtInstanceEntry::copy_clipboard() { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
void QtInstanceEntry::paste_clipboard() { assert(false && "Not implemented yet"); }
|
|
|
|
|
|
|
|
void QtInstanceEntry::set_alignment(TxtAlign) { assert(false && "Not implemented yet"); }
|
|
|
|
|
tdf#130857 qt weld: Notify about spinbox combined value+text change
While QtInstanceEntry generally takes care of handling signals
for the spinbox's QLineEdit, this doesn't work when the value
is changed as a result of setting a new spinbox value (e.g.
by using the spinbox buttons), as the QLineEdit signals are blocked
then, see QAbstractSpinBoxPrivate::updateEdit in qtbase [1].
Therefore, connect the QDoubleSpinBox::textChanged signal
to the slot that calls signal_changed() instead to ensure
it gets called nonetheless, and disconnect from the other signal.
While at it, also add a SolarMutexGuard when calling the
signal.
This fixes the issue noticed with the "Go to Page"
dialog mentioned in previous commit
Change-Id: I1f24cf3925e945ae78a9f1646535e08736cd8786
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Wed Nov 27 23:53:58 2024 +0100
tdf#130857 qt weld: Support "Go to Page" dialog
as:
> One issue seen with the dialog is that by using the
> up arrow of the spinbox to increase the value, it
> is currently possible to increase the value
> beyond the maximum value (last page number),
> while this is not the case when typing a number
> into the box manually.
>
> This is because the GotoPageDlg::PageModifiedHdl
> handler currently only gets called for the
> latter case, not the former one, despite
>
> Change-Id: Ie19bc852f4ceed0fa79565302975376db7126ea4
> Author: Michael Weghorn <m.weghorn@posteo.de>
> Date: Wed Nov 27 22:53:55 2024 +0100
>
> tdf#130857 qt weld: Also notify about programmatic text changes
>
> and will be addressed in a separate commit.
[1] https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qabstractspinbox.cpp?id=ced47a590aeb85953a16eaf362887f14c2815c45#n1790
Change-Id: Ifba9a0877442f9e84f0103d8aab202ae3583c5cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177451
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-28 00:30:10 +01:00
|
|
|
void QtInstanceEntry::handleTextChanged()
|
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
signal_changed();
|
|
|
|
}
|
|
|
|
|
2024-11-18 09:33:05 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|