mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
WIP: Working on proper sizing and layout of the tags display
This commit is contained in:
parent
571f7ba6e4
commit
e7553eaed8
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>530</width>
|
<width>530</width>
|
||||||
<height>257</height>
|
<height>296</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||||
@ -260,8 +260,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>157</width>
|
<width>152</width>
|
||||||
<height>63</height>
|
<height>57</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||||
@ -481,13 +481,28 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1" colspan="5">
|
<item row="2" column="1" colspan="5">
|
||||||
<widget class="TagsEdit" name="entryTagsList" native="true">
|
<widget class="TagsEdit" name="entryTagsList">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>80</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::ClickFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="accessibleName">
|
<property name="accessibleName">
|
||||||
<string>Tags list</string>
|
<string>Tags list</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="5">
|
<item row="1" column="5">
|
||||||
@ -1218,7 +1233,7 @@
|
|||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>TagsEdit</class>
|
<class>TagsEdit</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QScrollArea</extends>
|
||||||
<header>gui/tag/TagsEdit.h</header>
|
<header>gui/tag/TagsEdit.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
@ -144,6 +144,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="TagsEdit" name="tagsList">
|
<widget class="TagsEdit" name="tagsList">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>16777215</width>
|
<width>16777215</width>
|
||||||
|
@ -339,7 +339,8 @@ struct TagsEdit::Impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
void insertText(const QString& text) {
|
void insertText(const QString& text) {
|
||||||
currentText().insert(cursor, text);
|
Q_ASSERT(tags.editingIndex() != tags.end());
|
||||||
|
tags.editingIndex()->text.insert(cursor, text);
|
||||||
moveCursor(cursor + text.size(), false);
|
moveCursor(cursor + text.size(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +369,7 @@ struct TagsEdit::Impl
|
|||||||
void setCurrentText(const QString& text)
|
void setCurrentText(const QString& text)
|
||||||
{
|
{
|
||||||
Q_ASSERT(tags.editingIndex() != tags.end());
|
Q_ASSERT(tags.editingIndex() != tags.end());
|
||||||
currentText() = text;
|
tags.editingIndex()->text = text;
|
||||||
moveCursor(currentText().length(), false);
|
moveCursor(currentText().length(), false);
|
||||||
updateDisplayText();
|
updateDisplayText();
|
||||||
calcRectsAndUpdateScrollRanges();
|
calcRectsAndUpdateScrollRanges();
|
||||||
@ -391,7 +392,7 @@ struct TagsEdit::Impl
|
|||||||
// and ensures Invariant-1.
|
// and ensures Invariant-1.
|
||||||
void editNewTag(const iterator& i)
|
void editNewTag(const iterator& i)
|
||||||
{
|
{
|
||||||
currentText() = currentText().trimmed();
|
tags.editingIndex()->text = currentText().trimmed();
|
||||||
auto inserted_at = tags.insert(i, Tag());
|
auto inserted_at = tags.insert(i, Tag());
|
||||||
setEditingIndex(inserted_at);
|
setEditingIndex(inserted_at);
|
||||||
moveCursor(0, false);
|
moveCursor(0, false);
|
||||||
@ -419,7 +420,7 @@ struct TagsEdit::Impl
|
|||||||
void removeSelection()
|
void removeSelection()
|
||||||
{
|
{
|
||||||
cursor = select_start;
|
cursor = select_start;
|
||||||
currentText().remove(cursor, select_size);
|
tags.editingIndex()->text.remove(cursor, select_size);
|
||||||
deselectAll();
|
deselectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +429,7 @@ struct TagsEdit::Impl
|
|||||||
if (hasSelection()) {
|
if (hasSelection()) {
|
||||||
removeSelection();
|
removeSelection();
|
||||||
} else {
|
} else {
|
||||||
currentText().remove(--cursor, 1);
|
tags.editingIndex()->text.remove(--cursor, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +619,6 @@ private:
|
|||||||
int select_start;
|
int select_start;
|
||||||
int select_size;
|
int select_size;
|
||||||
bool cross_deleter;
|
bool cross_deleter;
|
||||||
int hscroll{0};
|
|
||||||
QTextLayout text_layout;
|
QTextLayout text_layout;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -641,11 +641,8 @@ public:
|
|||||||
const auto r = currentRect();
|
const auto r = currentRect();
|
||||||
const auto txt_p = r.topLeft() + QPoint(TAG_INNER.left(), ((r.height() - fontHeight) / 2));
|
const auto txt_p = r.topLeft() + QPoint(TAG_INNER.left(), ((r.height() - fontHeight) / 2));
|
||||||
|
|
||||||
// Nothing to draw. Don't draw anything to avoid adding text margins.
|
|
||||||
if (!it->isEmpty()) {
|
|
||||||
// draw not terminated tag
|
// draw not terminated tag
|
||||||
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
|
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
|
||||||
}
|
|
||||||
|
|
||||||
// draw cursor
|
// draw cursor
|
||||||
if (drawCursor) {
|
if (drawCursor) {
|
||||||
@ -663,19 +660,8 @@ TagsEdit::TagsEdit(QWidget* parent)
|
|||||||
, impl(new Impl(this))
|
, impl(new Impl(this))
|
||||||
, completer(new QCompleter)
|
, completer(new QCompleter)
|
||||||
{
|
{
|
||||||
QSizePolicy size_policy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
setReadOnly(false);
|
||||||
size_policy.setHeightForWidth(true);
|
|
||||||
setSizePolicy(size_policy);
|
|
||||||
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
|
||||||
viewport()->setCursor(Qt::IBeamCursor);
|
|
||||||
setAttribute(Qt::WA_InputMethodEnabled, true);
|
|
||||||
setMouseTracking(true);
|
|
||||||
|
|
||||||
setupCompleter();
|
setupCompleter();
|
||||||
setCursorVisible(hasFocus());
|
|
||||||
impl->updateDisplayText();
|
|
||||||
|
|
||||||
viewport()->setContentsMargins(TAG_H_SPACING, TAG_V_SPACING, TAG_H_SPACING, TAG_V_SPACING);
|
viewport()->setContentsMargins(TAG_H_SPACING, TAG_V_SPACING, TAG_H_SPACING, TAG_V_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,6 +680,7 @@ void TagsEdit::setReadOnly(bool readOnly)
|
|||||||
setCursor(Qt::IBeamCursor);
|
setCursor(Qt::IBeamCursor);
|
||||||
setAttribute(Qt::WA_InputMethodEnabled, true);
|
setAttribute(Qt::WA_InputMethodEnabled, true);
|
||||||
}
|
}
|
||||||
|
setMouseTracking(!m_readOnly);
|
||||||
impl->setReadOnly(m_readOnly);
|
impl->setReadOnly(m_readOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,24 +824,20 @@ void TagsEdit::mousePressEvent(QMouseEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TagsEdit::sizeHint() const
|
QSize TagsEdit::viewportSizeHint() const
|
||||||
{
|
{
|
||||||
return minimumSizeHint();
|
return impl->updateTagRenderStates({0, 0, width(), 0}).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TagsEdit::minimumSizeHint() const
|
bool TagsEdit::hasHeightForWidth() const
|
||||||
{
|
{
|
||||||
ensurePolished();
|
return true;
|
||||||
QFontMetrics fm = fontMetrics();
|
|
||||||
QRect rect(0, 0, fm.maxWidth() + TAG_CROSS_PADDING + TAG_CROSS_WIDTH, fm.height() + fm.leading());
|
|
||||||
rect += TAG_INNER + contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
|
||||||
return rect.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TagsEdit::heightForWidth(int w) const
|
int TagsEdit::heightForWidth(int w) const
|
||||||
{
|
{
|
||||||
const auto content_width = w;
|
const auto content_width = w;
|
||||||
QRect contents_rect(0, 0, content_width, 100);
|
QRect contents_rect(0, 0, content_width, 32);
|
||||||
contents_rect -= contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
contents_rect -= contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
||||||
contents_rect = impl->updateTagRenderStates(contents_rect);
|
contents_rect = impl->updateTagRenderStates(contents_rect);
|
||||||
contents_rect += contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
contents_rect += contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
||||||
|
@ -37,8 +37,7 @@ public:
|
|||||||
explicit TagsEdit(QWidget* parent = nullptr);
|
explicit TagsEdit(QWidget* parent = nullptr);
|
||||||
~TagsEdit() override;
|
~TagsEdit() override;
|
||||||
|
|
||||||
QSize sizeHint() const override;
|
bool hasHeightForWidth() const override;
|
||||||
QSize minimumSizeHint() const override;
|
|
||||||
int heightForWidth(int w) const override;
|
int heightForWidth(int w) const override;
|
||||||
|
|
||||||
void setReadOnly(bool readOnly);
|
void setReadOnly(bool readOnly);
|
||||||
@ -60,6 +59,7 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
void hideEvent(QHideEvent* event) override;
|
void hideEvent(QHideEvent* event) override;
|
||||||
|
QSize viewportSizeHint() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isAcceptableInput(QKeyEvent const* event) const;
|
bool isAcceptableInput(QKeyEvent const* event) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user