mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 06:49:46 -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>
|
||||
<y>0</y>
|
||||
<width>530</width>
|
||||
<height>257</height>
|
||||
<height>296</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
@ -260,8 +260,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>157</width>
|
||||
<height>63</height>
|
||||
<width>152</width>
|
||||
<height>57</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
@ -481,13 +481,28 @@
|
||||
</layout>
|
||||
</item>
|
||||
<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">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string>Tags list</string>
|
||||
</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>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
@ -1218,7 +1233,7 @@
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>TagsEdit</class>
|
||||
<extends>QWidget</extends>
|
||||
<extends>QScrollArea</extends>
|
||||
<header>gui/tag/TagsEdit.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
|
@ -144,6 +144,12 @@
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="TagsEdit" name="tagsList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
|
@ -339,7 +339,8 @@ struct TagsEdit::Impl
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -368,7 +369,7 @@ struct TagsEdit::Impl
|
||||
void setCurrentText(const QString& text)
|
||||
{
|
||||
Q_ASSERT(tags.editingIndex() != tags.end());
|
||||
currentText() = text;
|
||||
tags.editingIndex()->text = text;
|
||||
moveCursor(currentText().length(), false);
|
||||
updateDisplayText();
|
||||
calcRectsAndUpdateScrollRanges();
|
||||
@ -391,7 +392,7 @@ struct TagsEdit::Impl
|
||||
// and ensures Invariant-1.
|
||||
void editNewTag(const iterator& i)
|
||||
{
|
||||
currentText() = currentText().trimmed();
|
||||
tags.editingIndex()->text = currentText().trimmed();
|
||||
auto inserted_at = tags.insert(i, Tag());
|
||||
setEditingIndex(inserted_at);
|
||||
moveCursor(0, false);
|
||||
@ -419,7 +420,7 @@ struct TagsEdit::Impl
|
||||
void removeSelection()
|
||||
{
|
||||
cursor = select_start;
|
||||
currentText().remove(cursor, select_size);
|
||||
tags.editingIndex()->text.remove(cursor, select_size);
|
||||
deselectAll();
|
||||
}
|
||||
|
||||
@ -428,7 +429,7 @@ struct TagsEdit::Impl
|
||||
if (hasSelection()) {
|
||||
removeSelection();
|
||||
} else {
|
||||
currentText().remove(--cursor, 1);
|
||||
tags.editingIndex()->text.remove(--cursor, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -618,7 +619,6 @@ private:
|
||||
int select_start;
|
||||
int select_size;
|
||||
bool cross_deleter;
|
||||
int hscroll{0};
|
||||
QTextLayout text_layout;
|
||||
|
||||
public:
|
||||
@ -641,11 +641,8 @@ public:
|
||||
const auto r = currentRect();
|
||||
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
|
||||
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
|
||||
}
|
||||
// draw not terminated tag
|
||||
text_layout.draw(&p, txt_p - scrollOffsets, formatting());
|
||||
|
||||
// draw cursor
|
||||
if (drawCursor) {
|
||||
@ -663,19 +660,8 @@ TagsEdit::TagsEdit(QWidget* parent)
|
||||
, impl(new Impl(this))
|
||||
, completer(new QCompleter)
|
||||
{
|
||||
QSizePolicy size_policy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
||||
size_policy.setHeightForWidth(true);
|
||||
setSizePolicy(size_policy);
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
setAttribute(Qt::WA_InputMethodEnabled, true);
|
||||
setMouseTracking(true);
|
||||
|
||||
setReadOnly(false);
|
||||
setupCompleter();
|
||||
setCursorVisible(hasFocus());
|
||||
impl->updateDisplayText();
|
||||
|
||||
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);
|
||||
setAttribute(Qt::WA_InputMethodEnabled, true);
|
||||
}
|
||||
setMouseTracking(!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();
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
||||
int TagsEdit::heightForWidth(int w) const
|
||||
{
|
||||
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 = impl->updateTagRenderStates(contents_rect);
|
||||
contents_rect += contentsMargins() + viewport()->contentsMargins() + viewportMargins();
|
||||
|
@ -37,8 +37,7 @@ public:
|
||||
explicit TagsEdit(QWidget* parent = nullptr);
|
||||
~TagsEdit() override;
|
||||
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
bool hasHeightForWidth() const override;
|
||||
int heightForWidth(int w) const override;
|
||||
|
||||
void setReadOnly(bool readOnly);
|
||||
@ -60,6 +59,7 @@ protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void hideEvent(QHideEvent* event) override;
|
||||
QSize viewportSizeHint() const override;
|
||||
|
||||
private:
|
||||
bool isAcceptableInput(QKeyEvent const* event) const;
|
||||
|
Loading…
Reference in New Issue
Block a user