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

View File

@@ -90,8 +90,8 @@ void MsgWidget::on_editText_textChanged()
if(textRect.width() > widthEdit) 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) if(textRect.width() > widthEdit)
{ {
@@ -109,13 +109,12 @@ void MsgWidget::on_editText_textChanged()
{ {
this->setFixedHeight(textRect.height() + X + 20 + 30); this->setFixedHeight(textRect.height() + X + 20 + 30);
ui->editText->setFixedHeight(textRect.height() + X); ui->editText->setFixedHeight(textRect.height() + X);
} }
} }
else else
{//В одну строку {//В одну строку
this->setFixedHeight(textRect.height() + X + 20 + 30);
ui->editText->setFixedWidth(textRect.width() + X); ui->editText->setFixedWidth(textRect.width() + X);
ui->editText->setFixedHeight(textRect.height() + 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); explicit MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent = nullptr);
~MsgWidget(); ~MsgWidget();
void setAligneAvatarLeft();
void setAligneAvatarRight();
void setAvatar(QString avatar);
void setWidth(int width);
void setText(QString text); void setText(QString text);
void setTime(QString timeStr); void setTime(QString timeStr);
private:
void setAligneAvatarLeft();
void setAligneAvatarRight();
void setAvatar(QString avatar);
void setWidth(int width);
private slots: private slots:
void on_editText_textChanged(); void on_editText_textChanged();