Skip to content

Commit 72dc581

Browse files
committed
[Frontend] [App Drawer] Fixed: App drawer UI issues
1 parent 88c1d4f commit 72dc581

6 files changed

Lines changed: 274 additions & 17 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ set(FRONTEND_SOURCES
170170
src/components/app_drawer/app_drawer.cc
171171
src/components/app_drawer/app_drawer_item.h
172172
src/components/app_drawer/app_drawer_item.cc
173+
src/components/app_drawer/app_drawer_search_item.h
174+
src/components/app_drawer/app_drawer_search_item.cc
173175
src/components/krunner_btn/krunner_btn.h
174176
src/components/krunner_btn/krunner_btn.cc
175177
src/components/battery_indicator/battery_indicator.h

‎locales/HuskyPanel_zh_CN.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@
5656
<translation type="obsolete">工具</translation>
5757
</message>
5858
<message>
59-
<location filename="../src/components/app_drawer/app_drawer.cc" line="607"/>
59+
<location filename="../src/components/app_drawer/app_drawer.cc" line="608"/>
6060
<source>Sleep</source>
6161
<translation type="unfinished">睡眠</translation>
6262
</message>
6363
<message>
64-
<location filename="../src/components/app_drawer/app_drawer.cc" line="617"/>
64+
<location filename="../src/components/app_drawer/app_drawer.cc" line="618"/>
6565
<source>Hibernate</source>
6666
<translation type="unfinished">休眠</translation>
6767
</message>
6868
<message>
69-
<location filename="../src/components/app_drawer/app_drawer.cc" line="627"/>
69+
<location filename="../src/components/app_drawer/app_drawer.cc" line="628"/>
7070
<source>Reboot</source>
7171
<translation type="unfinished">重启</translation>
7272
</message>
7373
<message>
74-
<location filename="../src/components/app_drawer/app_drawer.cc" line="637"/>
74+
<location filename="../src/components/app_drawer/app_drawer.cc" line="638"/>
7575
<source>Shut down</source>
7676
<translation type="unfinished">关机</translation>
7777
</message>
7878
<message>
79-
<location filename="../src/components/app_drawer/app_drawer.cc" line="651"/>
79+
<location filename="../src/components/app_drawer/app_drawer.cc" line="652"/>
8080
<source>Session</source>
8181
<translation type="unfinished">会话选项</translation>
8282
</message>

‎src/components/app_drawer/app_drawer.cc‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ AppDrawer::AppDrawer(QWidget *parent) : QWidget(parent) {
341341
search_drawer_->setWidget(actual_search_drawer_);
342342

343343
if (search_layout_ == nullptr) {
344-
search_layout_ = new QGridLayout();
344+
search_layout_ = new QVBoxLayout();
345345
search_layout_->setContentsMargins(16, 16, 16, 16);
346346
search_layout_->setSpacing(8);
347+
search_layout_->setAlignment(Qt::AlignTop);
347348
}
348349
actual_search_drawer_->setLayout(search_layout_);
349350

@@ -783,18 +784,13 @@ int AppDrawer::UpdateAppDrawerItems() {
783784
}
784785
}
785786

786-
// Search drawer (uses all apps)
787+
// Search drawer
787788
if (search_layout_ != nullptr) {
788-
cur_col = 0;
789-
cur_row = 0;
790789
for (const auto& app : app_infos_) {
791-
AppDrawerItem * item_gen = new AppDrawerItem(app);
792-
search_layout_->addWidget(item_gen, cur_row, cur_col);
793-
cur_col += 1;
794-
if (cur_col > 3) {
795-
cur_col = 0;
796-
cur_row += 1;
797-
}
790+
AppDrawerSearchItem * item_gen = new AppDrawerSearchItem(app);
791+
QObject::connect(this, &AppDrawer::DrawerItemFilterUpdated, item_gen,
792+
&AppDrawerSearchItem::UpdateFilter);
793+
search_layout_->addWidget(item_gen);
798794
}
799795
}
800796

@@ -972,6 +968,12 @@ int AppDrawer::UpdateAppDrawerItems() {
972968
}
973969

974970
void AppDrawer::OnSearchBarTextChanged(const QString& text) {
971+
if (drawer_stack_ != nullptr && drawer_stack_->currentIndex() != 1 &&
972+
search_apps_btn_ != nullptr && !text.isEmpty()) {
973+
QMetaObject::invokeMethod(search_apps_btn_, "GroupSelected",
974+
Q_ARG(QString, "app_drawer_side_pane"), Q_ARG(QString, "search_apps"));
975+
}
976+
975977
emit DrawerItemFilterUpdated(text);
976978
}
977979

‎src/components/app_drawer/app_drawer.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/theme_loader/theme_loader.h"
2929
#include "src/components/app_drawer/app_drawer_side_pane_item.h"
3030
#include "src/components/app_drawer/app_drawer_item.h"
31+
#include "src/components/app_drawer/app_drawer_search_item.h"
3132
#include "src/info_server/application_info/application_info.h"
3233
#include "src/translation_loader/translation_loader.h"
3334

@@ -73,7 +74,7 @@ class AppDrawer : public QWidget {
7374

7475
QScrollArea * search_drawer_ = nullptr;
7576
QWidget * actual_search_drawer_ = nullptr;
76-
QGridLayout * search_layout_ = nullptr;
77+
QVBoxLayout * search_layout_ = nullptr;
7778

7879
QScrollArea * audio_video_drawer_ = nullptr;
7980
QWidget * actual_audio_video_drawer_ = nullptr;
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* Copyright (C) 2026 MarcusPy827
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <QVBoxLayout>
19+
#include <QHBoxLayout>
20+
#include <QSpacerItem>
21+
#include <QProcess>
22+
#include <QRegularExpression>
23+
#include <QMouseEvent>
24+
#include <QFontMetrics>
25+
#include <QSizePolicy>
26+
#include <QMargins>
27+
28+
#include <string>
29+
30+
#include "absl/log/log.h"
31+
#include "absl/log/check.h"
32+
#include "absl/strings/str_format.h"
33+
#include "absl/strings/str_cat.h"
34+
35+
#include "src/components/app_drawer/app_drawer_search_item.h"
36+
37+
namespace panel {
38+
namespace frontend {
39+
40+
AppDrawerSearchItem::AppDrawerSearchItem(const AppInfo& info, QWidget
41+
*parent) : QWidget(parent) {
42+
this->info_ = info;
43+
this->setProperty("class", "app_drawer_search_item");
44+
this->setCursor(Qt::PointingHandCursor);
45+
46+
QHBoxLayout * layout_gen = new QHBoxLayout;
47+
layout_gen->setContentsMargins(0, 0, 0, 0);
48+
layout_gen->setSpacing(6);
49+
layout_gen->setAlignment(Qt::AlignLeft | Qt::AlignTop);
50+
this->setLayout(layout_gen);
51+
52+
if (btn_ == nullptr) {
53+
btn_ = new QToolButton();
54+
btn_->setProperty("class", "drawer_item_btn");
55+
btn_->setIconSize(QSize(48, 48));
56+
btn_->setMinimumSize(QSize(48, 48));
57+
}
58+
btn_->setAttribute(Qt::WA_TransparentForMouseEvents, true);
59+
btn_->setIcon(QIcon::fromTheme(info_.icon_name));
60+
layout_gen->addWidget(btn_);
61+
62+
QVBoxLayout * info_layout = new QVBoxLayout;
63+
info_layout->setContentsMargins(0, 0, 0, 0);
64+
info_layout->setSpacing(0);
65+
layout_gen->addLayout(info_layout);
66+
67+
if (title_ == nullptr) {
68+
title_ = new QLabel();
69+
title_->setProperty("class", "app_drawer_item_label");
70+
title_->setAttribute(Qt::WA_TransparentForMouseEvents, true);
71+
}
72+
title_->setText("<b>" + info_.name + "</b>");
73+
info_layout->addWidget(title_);
74+
75+
if (!info_.comment.isEmpty()) {
76+
if (comment_ == nullptr) {
77+
comment_ = new QLabel();
78+
comment_->setProperty("class", "app_drawer_item_label");
79+
comment_->setAttribute(Qt::WA_TransparentForMouseEvents, true);
80+
comment_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
81+
comment_->setMinimumWidth(0);
82+
comment_->setWordWrap(false);
83+
}
84+
raw_comment_ = info_.comment;
85+
comment_->setToolTip(raw_comment_);
86+
info_layout->addWidget(comment_);
87+
UpdateCommentElide();
88+
}
89+
}
90+
91+
AppDrawerSearchItem::~AppDrawerSearchItem() {
92+
LOG(INFO) << absl::StrCat("AppDrawerSearchItem is being deleted.");
93+
}
94+
95+
void AppDrawerSearchItem::mousePressEvent(QMouseEvent *event) {
96+
if (event->button() == Qt::LeftButton) {
97+
Launch();
98+
event->accept();
99+
return;
100+
}
101+
102+
QWidget::mousePressEvent(event);
103+
}
104+
105+
void AppDrawerSearchItem::resizeEvent(QResizeEvent *event) {
106+
QWidget::resizeEvent(event);
107+
UpdateCommentElide();
108+
}
109+
110+
void AppDrawerSearchItem::showEvent(QShowEvent *event) {
111+
QWidget::showEvent(event);
112+
UpdateCommentElide();
113+
}
114+
115+
void AppDrawerSearchItem::UpdateCommentElide() {
116+
if (comment_ == nullptr || raw_comment_.isEmpty()) {
117+
return;
118+
}
119+
120+
const auto *layout_gen = qobject_cast<QHBoxLayout*>(layout());
121+
int available_width = comment_->width() * 0.8;
122+
if (layout_gen != nullptr) {
123+
const QMargins margins = layout_gen->contentsMargins();
124+
available_width = this->width() - margins.left() - margins.right() -
125+
btn_->width() - layout_gen->spacing();
126+
available_width *= 0.95;
127+
}
128+
129+
if (available_width <= 0) {
130+
comment_->setText(raw_comment_);
131+
return;
132+
}
133+
134+
const QFontMetrics metrics(comment_->font());
135+
comment_->setText(metrics.elidedText(raw_comment_, Qt::ElideRight,
136+
available_width));
137+
}
138+
139+
void AppDrawerSearchItem::Launch() {
140+
LOG(INFO) << absl::StrFormat("Launching application: %s",
141+
info_.name.toStdString());
142+
143+
if (info_.exec.isEmpty()) {
144+
LOG(ERROR) << absl::StrCat(
145+
"No executable command found for application: ",
146+
info_.name.toStdString(), ". Launch aborted.");
147+
return;
148+
}
149+
150+
QString raw_exec = info_.exec;
151+
static const QRegularExpression field_regex(
152+
QStringLiteral("\\s%[fFuUdDnNickvm]"));
153+
QString clean_exec = raw_exec.replace(field_regex, QString());
154+
155+
std::string cmd = "(" + clean_exec.toStdString() + ") &";
156+
int state = std::system(cmd.c_str());
157+
if (state != 0) {
158+
LOG(ERROR) << absl::StrCat(
159+
"Failed to launch application: ", info_.name.toStdString(),
160+
" with command: ", clean_exec.toStdString());
161+
}
162+
}
163+
164+
void AppDrawerSearchItem::UpdateFilter(const QString& keyword) {
165+
bool should_show = false;
166+
if (info_.name.contains(keyword, Qt::CaseInsensitive)) {
167+
should_show = true;
168+
} else if (info_.generic_name.contains(keyword, Qt::CaseInsensitive)) {
169+
should_show = true;
170+
} else if (info_.comment.contains(keyword, Qt::CaseInsensitive)) {
171+
should_show = true;
172+
}
173+
174+
if (should_show) {
175+
if (!this->isVisible()) {
176+
this->setVisible(true);
177+
}
178+
} else {
179+
if (this->isVisible()) {
180+
this->setVisible(false);
181+
}
182+
}
183+
}
184+
185+
} // namespace frontend
186+
} // namespace panel
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2026 MarcusPy827
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef SRC_COMPONENTS_APP_DRAWER_APP_DRAWER_SEARCH_ITEM_H_
19+
#define SRC_COMPONENTS_APP_DRAWER_APP_DRAWER_SEARCH_ITEM_H_
20+
21+
#include <QWidget>
22+
#include <QString>
23+
#include <QLabel>
24+
#include <QToolButton>
25+
#include <QMouseEvent>
26+
#include <QResizeEvent>
27+
#include <QShowEvent>
28+
29+
#include "src/info_server/application_info/application_info.h"
30+
31+
namespace panel {
32+
namespace frontend {
33+
34+
class AppDrawerSearchItem : public QWidget {
35+
Q_OBJECT
36+
37+
public:
38+
explicit AppDrawerSearchItem(const AppInfo& info, QWidget * parent = nullptr);
39+
~AppDrawerSearchItem();
40+
AppInfo GetAppInfo();
41+
42+
public slots:
43+
void UpdateFilter(const QString& keyword);
44+
45+
protected:
46+
void mousePressEvent(QMouseEvent *event) override;
47+
void resizeEvent(QResizeEvent *event) override;
48+
void showEvent(QShowEvent *event) override;
49+
50+
private:
51+
QToolButton * btn_ = nullptr;
52+
QLabel * title_ = nullptr;
53+
QLabel * comment_ = nullptr;
54+
AppInfo info_ = {};
55+
QString raw_comment_;
56+
57+
void UpdateCommentElide();
58+
59+
private slots:
60+
void Launch();
61+
};
62+
63+
} // namespace frontend
64+
} // namespace panel
65+
66+
#endif // SRC_COMPONENTS_APP_DRAWER_APP_DRAWER_SEARCH_ITEM_H_

0 commit comments

Comments
 (0)