Skip to content

Commit 96cb0a1

Browse files
authored
[201_37] 图片悬浮菜单固定高度 (#2320)
1 parent 1586d55 commit 96cb0a1

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

TeXmacs/progs/generic/format-edit.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@
173173
(string=? (tree->string (tree-ref t 0)) "par-mode")
174174
(>= (tree-arity t) 3))
175175
(tree-set! t 1 align)
176-
(debug-message "std-warning" "Invalid tree structure for set-image-alignment")))
176+
(debug-message "std-warning" "Invalid tree structure for set-image-alignment" "\n")))
177177

178178
(tm-define (get-image-alignment t)
179179
(if (and (tree-is? t 'with)
180180
(tree-is? (tree-ref t 0) 'string)
181181
(string=? (tree->string (tree-ref t 0)) "par-mode")
182182
(>= (tree-arity t) 3))
183183
(tree->string (tree-ref t 1))
184-
(debug-message "std-warning" "Invalid tree structure for get-image-alignment")))
184+
(debug-message "std-warning" "Invalid tree structure for get-image-alignment" "\n")))
185185

186186
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187187
;; Inserting and toggling with-like tags

TeXmacs/tests/tmu/201_37.tmu

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

devel/201_37.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
+ 测试左对齐、居中、右对齐按钮功能是否正常
1111
+ 弹出菜单后,上下滚动页面,菜单应始终保持在图片上方
1212
+ 查看当前对齐方式所对应的按钮是否正常高亮
13+
+ 按住ctrl/command,滚动滚轮,查看菜单大小是否跟随变化,以及悬浮菜单上边缘是否介于两行之间。
14+
+ 按住ctrl/command,持续缩小,通过 **(get-window-zoom-factor)** 获取页面缩放值, 当缩放值在 **0.35320088300220753** (即大概35.3%)及以下时,菜单应消失。
15+
16+
## 2025/12/22 图片悬浮菜单固定高度
17+
18+
### What
19+
+ 让图片悬浮菜单固定高度为单行段落,且能够随缩放变化大小。
20+
+ 缩放很小的时候坐标会有问题,但此时图标已经非常小,显示菜单已经没有意义,因此在缩放因子<=0.16时让菜单取消显示。
1321

1422
## 2025/12/22 对齐方式按钮突出显示
1523

src/Plugins/Qt/QTMImagePopup.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,25 @@ QTMImagePopup::QTMImagePopup (QWidget* parent, qt_simple_widget_rep* owner)
3939
effect->setOffset (0, 4);
4040
effect->setColor (QColor (0, 0, 0, 120));
4141
this->setGraphicsEffect (effect);
42-
43-
QScreen* Screen= QGuiApplication::primaryScreen ();
44-
const double Dpi = Screen ? Screen->logicalDotsPerInch () : 96.0;
45-
const double Scale = Dpi / 96.0;
46-
#if defined(Q_OS_MAC)
47-
const int IconSize= int (50 * Scale);
48-
#else
49-
const int IconSize= int (40 * Scale);
50-
#endif
51-
5242
leftBtn= new QToolButton ();
5343
leftBtn->setObjectName ("image-align-button");
5444
leftBtn->setProperty ("icon-name", "left");
5545
leftBtn->setIcon (QIcon (":/window-bar/left-align.svg"));
56-
leftBtn->setIconSize (QSize (IconSize, IconSize));
5746
leftBtn->setCheckable (true);
5847
middleBtn= new QToolButton ();
5948
middleBtn->setObjectName ("image-align-button");
6049
middleBtn->setProperty ("icon-name", "center");
6150
middleBtn->setIcon (QIcon (":/window-bar/middle-align.svg"));
62-
middleBtn->setIconSize (QSize (IconSize, IconSize));
6351
middleBtn->setCheckable (true);
6452
rightBtn= new QToolButton ();
6553
rightBtn->setObjectName ("image-align-button");
6654
rightBtn->setProperty ("icon-name", "right");
6755
rightBtn->setIcon (QIcon (":/window-bar/right-align.svg"));
68-
rightBtn->setIconSize (QSize (IconSize, IconSize));
6956
rightBtn->setCheckable (true);
7057
ocrBtn= new QToolButton ();
7158
ocrBtn->setObjectName ("image-align-button");
7259
ocrBtn->setProperty ("icon-name", "ocr");
7360
ocrBtn->setIcon (QIcon (":/window-bar/ocr.svg"));
74-
ocrBtn->setIconSize (QSize (IconSize, IconSize));
7561
QButtonGroup* alignGroup= new QButtonGroup (this);
7662
alignGroup->addButton (leftBtn);
7763
alignGroup->addButton (middleBtn);
@@ -101,7 +87,11 @@ void
10187
QTMImagePopup::showImagePopup (rectangle selr, double magf, int scroll_x,
10288
int scroll_y, int canvas_x) {
10389
cachePosition (selr, magf, scroll_x, scroll_y, canvas_x);
104-
this->adjustSize ();
90+
if (cached_magf <= 0.16) {
91+
setFixedSize (0, 0);
92+
return;
93+
}
94+
autoSize ();
10595
int x, y;
10696
getCachedPosition (x, y);
10797
QPoint topLeft (x, y);
@@ -138,6 +128,26 @@ QTMImagePopup::updatePosition () {
138128
move (pos_x, pos_y);
139129
}
140130

131+
void
132+
QTMImagePopup::autoSize () {
133+
QScreen* Screen = QGuiApplication::primaryScreen ();
134+
const double Dpi = Screen ? Screen->logicalDotsPerInch () : 96.0;
135+
const double Scale = Dpi / 96.0;
136+
const int baseWidth = 200;
137+
const int baseHeight= 50;
138+
double totalScale= Scale * cached_magf * 3.3;
139+
#if defined(Q_OS_MAC)
140+
const int IconSize= int (50 * Scale);
141+
#else
142+
const int IconSize= int (40 * totalScale);
143+
#endif
144+
leftBtn->setIconSize (QSize (IconSize, IconSize));
145+
middleBtn->setIconSize (QSize (IconSize, IconSize));
146+
rightBtn->setIconSize (QSize (IconSize, IconSize));
147+
ocrBtn->setIconSize (QSize (IconSize, IconSize));
148+
setFixedSize (int (baseWidth * totalScale), int (baseHeight * totalScale));
149+
}
150+
141151
void
142152
QTMImagePopup::cachePosition (rectangle selr, double magf, int scroll_x,
143153
int scroll_y, int canvas_x) {

src/Plugins/Qt/QTMImagePopup.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class QTMImagePopup : public QWidget {
5050
void scrollBy (int x, int y);
5151
void setImageTree (tree t);
5252
void updateButtonStates ();
53+
void autoSize ();
5354

5455
protected:
5556
void cachePosition (rectangle selr, double magf, int scroll_x, int scroll_y,

0 commit comments

Comments
 (0)