Рефакт Message Item

This commit is contained in:
2025-09-11 14:48:38 +03:00
parent 2066925844
commit a5431175d9
3 changed files with 47 additions and 51 deletions

View File

@@ -23,7 +23,7 @@
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_Main">
<item>
<layout class="QVBoxLayout" name="verticalLayout_1" stretch="0">
<layout class="QVBoxLayout" name="verticalLayout_Dialog" stretch="0">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
@@ -42,7 +42,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_1">
<attribute name="title">
@@ -59,7 +59,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout_Input">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
@@ -86,46 +86,42 @@
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QToolButton" name="btnSend">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>65</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>1000</height>
</size>
</property>
<property name="text">
<string>Send</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/resources/icons/sendMsg.png</normaloff>:/resources/icons/sendMsg.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
</layout>
<widget class="QToolButton" name="btnSend">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>65</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>1000</height>
</size>
</property>
<property name="text">
<string>Send</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/resources/icons/sendMsg.png</normaloff>:/resources/icons/sendMsg.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
</widget>
</item>
</layout>
</item>

View File

@@ -90,8 +90,8 @@ void MsgWidget::on_editText_textChanged()
if(textRect.width() > widthEdit)
{//Не помещается в одну строку
textRect = metricsFont.boundingRect(QRect(0, 0, widthEdit, 1000), 0, text);
textRect = metricsFont.boundingRect(QRect(0, 0, widthEdit, 1000), 0, text);
if(textRect.width() > widthEdit)
{
@@ -109,13 +109,12 @@ void MsgWidget::on_editText_textChanged()
{
this->setFixedHeight(textRect.height() + X + 20 + 30);
ui->editText->setFixedHeight(textRect.height() + X);
}
}
else
{//В одну строку
this->setFixedHeight(textRect.height() + X + 20 + 30);
ui->editText->setFixedWidth(textRect.width() + X);
ui->editText->setFixedHeight(textRect.height() + X);
this->setFixedHeight(textRect.height() + X + 20 + 30);
}
}

View File

@@ -23,14 +23,15 @@ public:
explicit MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent = nullptr);
~MsgWidget();
void setAligneAvatarLeft();
void setAligneAvatarRight();
void setAvatar(QString avatar);
void setWidth(int width);
void setText(QString text);
void setTime(QString timeStr);
private:
void setAligneAvatarLeft();
void setAligneAvatarRight();
void setAvatar(QString avatar);
void setWidth(int width);
private slots:
void on_editText_textChanged();