tools/chatgui: input bar with emoji panel, custom tab bar, Ctrl+Enter multiline, scroll fixes
This commit is contained in:
1 parent
b667d6f352
commit
e50ca9978e
11 files changed
+521
-23
No files matched your search
@@ -0,0 +1,86 @@
|
||||
#include "emojipanel.h"
|
||||
#include "emoji.h"
|
||||
#include "emojitabbar.h"
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QTabWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace {
|
||||
|
||||
class EmojiTabWidget : public QTabWidget {
|
||||
public:
|
||||
using QTabWidget::setTabBar;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
EmojiPanel::EmojiPanel(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setStyleSheet("EmojiPanel { background: palette(window); }");
|
||||
buildPanel(builtinEmojiSet());
|
||||
hide();
|
||||
}
|
||||
|
||||
void EmojiPanel::showEvent(QShowEvent *event) {
|
||||
if (parentWidget()) {
|
||||
setFixedHeight(parentWidget()->height() / 2);
|
||||
}
|
||||
QWidget::showEvent(event);
|
||||
}
|
||||
|
||||
void EmojiPanel::buildPanel(const QVector<EmojiCategory> &categories) {
|
||||
auto *tabs = new EmojiTabWidget();
|
||||
tabs->setDocumentMode(true);
|
||||
tabs->setTabBar(new EmojiTabBar(tabs));
|
||||
tabs->setStyleSheet("QTabWidget::pane { border: none; background: rgba(255,255,255,0.6); }");
|
||||
|
||||
for (const auto &cat : categories) {
|
||||
tabs->addTab(buildCategoryPage(cat), cat.name);
|
||||
}
|
||||
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(tabs);
|
||||
}
|
||||
|
||||
QWidget *EmojiPanel::buildCategoryPage(const EmojiCategory &cat) {
|
||||
auto *scroll = new QScrollArea();
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scroll->setStyleSheet("QScrollArea { border: none; }");
|
||||
|
||||
auto *container = new QWidget();
|
||||
auto *grid = new QGridLayout(container);
|
||||
grid->setContentsMargins(4, 4, 4, 4);
|
||||
grid->setSpacing(2);
|
||||
|
||||
int cols = 9;
|
||||
for (int i = 0; i < cat.items.size(); ++i) {
|
||||
auto *btn = new QPushButton(cat.items[i].unicode, container);
|
||||
btn->setFixedSize(32, 32);
|
||||
btn->setCursor(Qt::PointingHandCursor);
|
||||
btn->setStyleSheet(
|
||||
"QPushButton { border: none; border-radius: 4px; font-size: 18px; background: transparent; }"
|
||||
"QPushButton:hover { background: rgba(0,0,0,0.08); }"
|
||||
);
|
||||
btn->setToolTip(cat.items[i].shortcode);
|
||||
connect(btn, &QPushButton::clicked, this, &EmojiPanel::onEmojiClicked);
|
||||
grid->addWidget(btn, i / cols, i % cols);
|
||||
}
|
||||
grid->setRowStretch(grid->rowCount(), 1);
|
||||
|
||||
scroll->setWidget(container);
|
||||
return scroll;
|
||||
}
|
||||
|
||||
void EmojiPanel::onEmojiClicked() {
|
||||
auto *btn = qobject_cast<QPushButton *>(sender());
|
||||
if (btn) {
|
||||
emit emojiSelected(btn->text());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user