make it closer to reality

This commit is contained in:
Minecon724 2024-09-04 15:20:20 +02:00
parent cb5c8afe1b
commit 67282dbd74
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
4 changed files with 93 additions and 2 deletions

12
pom.xml
View file

@ -15,6 +15,13 @@
<exec.mainClass>eu.m724.chaqt.Main</exec.mainClass>
</properties>
<repositories>
<repository>
<id>m724</id>
<url>https://git.m724.eu/api/packages/Minecon724/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.qtjambi</groupId>
@ -26,6 +33,11 @@
<artifactId>qtjambi-native-linux-x64</artifactId>
<version>6.7.2</version>
</dependency>
<dependency>
<groupId>eu.m724</groupId>
<artifactId>chatapi</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>

View file

@ -0,0 +1,14 @@
package eu.m724.chaqt;
import eu.m724.chatapi.chat.Chat;
public class ChatWindowViewModel {
private ChatWindowWidget widget;
private Chat chat;
public ChatWindowViewModel(ChatWindowWidget widget, Chat chat) {
this.widget = widget;
this.chat = chat;
}
}

View file

@ -0,0 +1,62 @@
package eu.m724.chaqt;
import eu.m724.chatapi.chat.Chat;
import io.qt.core.Qt;
import io.qt.widgets.*;
public class ChatWindowWidget extends QWidget {
private ChatWindowViewModel viewModel;
private QVBoxLayout layout;
private QTextEdit textEdit;
public ChatWindowWidget(Chat chat) {
this.viewModel = new ChatWindowViewModel(this, chat);
//
this.layout = new QVBoxLayout();
layout.setAlignment(Qt.AlignmentFlag.AlignBottom); // or top?
QWidget widget = new QWidget();
widget.setLayout(layout);
QScrollArea scrollArea = new QScrollArea();
scrollArea.setWidgetResizable(true);
scrollArea.setWidget(widget);
//
this.textEdit = new QTextEdit();
textEdit.setPlaceholderText("Write a message...");
textEdit.textChanged.connect(this, "handleComposerType()");
QPushButton sendButton = new QPushButton("Send");
QHBoxLayout composerLayout = new QHBoxLayout();
composerLayout.addWidget(textEdit);
composerLayout.addWidget(sendButton, 0, Qt.AlignmentFlag.AlignBottom);
QWidget composerWidget = new QWidget();
composerWidget.setLayout(composerLayout);
handleComposerType(); // TODO make it resizable and fix it
//
QVBoxLayout mainLayout = new QVBoxLayout();
mainLayout.addWidget(scrollArea, 1);
mainLayout.addWidget(composerWidget);
setLayout(mainLayout);
for (int i=0; i<10; i++) {
QPushButton pushButton = new QPushButton("hello");
layout.addWidget(pushButton);
}
}
public void handleComposerType() {
int height = (int) textEdit.document().size().height();
textEdit.setFixedHeight(height + textEdit.contentsMargins().top() + textEdit.contentsMargins().bottom());
}
}

View file

@ -1,5 +1,6 @@
package eu.m724.chaqt;
import eu.m724.chatapi.chat.Chat;
import io.qt.widgets.QApplication;
import io.qt.widgets.QMessageBox;
@ -8,8 +9,10 @@ public class Main {
public static void main(String[] args) {
QApplication.initialize(args);
HelloWorld hello = new HelloWorld();
hello.show();
Chat chat = new Chat();
ChatWindowWidget widget = new ChatWindowWidget(chat);
widget.show();
QApplication.exec();
}