Skip to content

Commit

Permalink
fix: Preview selector box size with content obscured
Browse files Browse the repository at this point in the history
  • Loading branch information
XMuli committed Aug 21, 2023
1 parent a23c210 commit 482c2dd
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/resources/config/config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[%General]
firstRun=true
font="SimSun,9"
font="Microsoft YaHei,9"
autoRun=true
asAdmin=false
logLevel=debug
Expand Down
2 changes: 1 addition & 1 deletion src/screen/datamaid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DataIni::DataIni(QObject *parent)
: QObject(parent)
, m_firstRun(true)
, m_lanuage("en_US")
, m_font("SimSun,9")
, m_font("Microsoft YaHei,9")
, m_autoRun(true)
, m_asAdmin(false)
, m_logLevel("debug")
Expand Down
4 changes: 2 additions & 2 deletions src/screen/rectcalcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ RectCalcu::RectCalcu(ScreenShot* pSrnShot)
, rtSel(0, 0, -1, -1)
, m_bClear(false)
, cursArea(CursorArea::Unknow)
, m_pSrnShot(pSrnShot)
, m_scrnShot(pSrnShot)
{
}

Expand All @@ -191,7 +191,7 @@ const QRect RectCalcu::getSelRect() const
return getRect(pos1, pos2);
} else if (scrnType == ScrnOperate::SO_Move) {
// TODO 2022.06.14: 单例改写了为 new 形式,故此处有一个 移动图形的 bug,且略感觉此获取方式有点不优雅
if (m_pSrnShot && m_pSrnShot->isSelBorder()) // 选中绘画的矩形
if (m_scrnShot && m_scrnShot->isSelBorder()) // 选中绘画的矩形
return rtSel.translated(pos2 - pos1);

return rtSel;
Expand Down
2 changes: 1 addition & 1 deletion src/screen/rectcalcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class RectCalcu
QRect rtSel; // 由 pos1, pos2 所得
bool m_bClear; // 当前清理状态
CursorArea cursArea; // 光标对应区域
ScreenShot* m_pSrnShot; // 用来判定 当前选中 移动 形状
ScreenShot* m_scrnShot; // 用来判定 当前选中 移动 形状
};

#endif //PICSHOT_RECTCALCU_H
98 changes: 39 additions & 59 deletions src/screen/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <QFileInfoList>
#include <QKeySequence>
#include <QHotkey>
#include <QFont>
#include <QString>
#include <QMetaEnum>
#include "../preference/prefmanage.h"
#include "../widget/xkeysequenceedit.h"
Expand All @@ -39,70 +41,55 @@ std::vector<std::tuple<QHotkey*, QString, QString, CaptureHelper::CaptureType>>

Tray::Tray(QObject *parent)
: QObject(parent)
, m_pSrnShot(nullptr)
, m_pPref(nullptr)
, m_trayIconMenu(new QMenu())
, m_scrnShot(nullptr)
, m_prefManage(nullptr)
, m_trayMenu(new QMenu())
, m_trayIcon(new QSystemTrayIcon(this))
//, m_hkManage(new HotkeySvs(this))
{
init();
initGlobalHotKeys();
DATAMAID->setAutoRun();

// QString t = QApplication::instance()->applicationDirPath() + "/../../pluginsimpl/watemark/RelWithDebInfo";
// QDir pluginsDir(t);
// QStringList nameFilters;
// nameFilters<<"*.so"<<"*.dylib"<<"*.dll";
// QFileInfoList plugins = pluginsDir.entryInfoList(nameFilters, QDir::NoDotAndDotDot | QDir::Files, QDir::Name);
//
// foreach(QFileInfo plugin, plugins){
// QPluginLoader pluginLoader(plugin.absoluteFilePath(), this);
// IPluginInterface *pPlugin=qobject_cast<IPluginInterface *>(pluginLoader.instance());
// if (pPlugin){
// QString temp= pPlugin->plugName();
//// QAction *action = new QAction(plugin_ptr->name());
//// editMenu->addAction(action);
//// editToolBar->addAction(action);
//// editPlugins[plugin_ptr->name()]=plugin_ptr;
//// connect(action,SIGNAL(triggered(bool)),this,SLOT(pluginPerform()));
//
//// pPlugin.unload();
// }else{
// qDebug()<<"bad plugin:"<<plugin.absoluteFilePath();
// }
// }
}

Tray::~Tray()
{
if (m_pSrnShot)
m_pSrnShot->deleteLater();

if (m_pPref)
m_pPref->deleteLater();
if (m_scrnShot) m_scrnShot->deleteLater();
if (m_prefManage) m_prefManage->deleteLater();

delete m_trayIconMenu;
m_trayIconMenu = nullptr;
delete m_trayMenu;
m_trayMenu = nullptr;
}

void Tray::init()
{
const auto& tFont = DATAMAID->paraValue("font").value<QString>().split(',');
QString fontFamily = "Microsoft YaHei";
int fontPointSize = 9;
if (tFont.size() == 2) {
fontFamily = tFont.at(0);
fontPointSize = tFont.at(1).toInt();
}

QFont font(fontFamily, fontPointSize);
qGuiApp->setFont(font);
m_trayMenu->setFont(font);

QAction* srnShot = new QAction(tr("ScreenShot"), this);
QAction* preference = new QAction(tr("Preference"), this);
QAction* quit = new QAction(tr("Quit"), this);

m_trayIconMenu->addAction(srnShot);
m_trayIconMenu->addAction(preference);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(quit);
m_trayMenu->addAction(srnShot);
m_trayMenu->addAction(preference);
m_trayMenu->addSeparator();
m_trayMenu->addAction(quit);

m_trayIcon->setIcon(QIcon(":/resources/logo/logo.png"));
m_trayIcon->setToolTip(tr(_PROJECT_NAME));
m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->setContextMenu(m_trayMenu);


connect(m_trayIcon, &QSystemTrayIcon::activated, this, &Tray::onActivated);
connect(srnShot, &QAction::triggered, this, &Tray::onSrnShot);
connect(srnShot, &QAction::triggered, this, &Tray::onScrnShot);
connect(preference, &QAction::triggered, this, &Tray::onPreference);
connect(quit, &QAction::triggered, [](){qApp->quit();});

Expand Down Expand Up @@ -141,7 +128,7 @@ void Tray::initGlobalHotKeys()
pHK = new QHotkey(QKeySequence(hotkey), true, qApp);
QMetaEnum enumSst = QMetaEnum::fromType<CaptureHelper::CaptureType>();
pHK->setObjectName(enumSst.valueToKey(sst));
connect(pHK, &QHotkey::activated, this, &Tray::onSrnShot);
connect(pHK, &QHotkey::activated, this, &Tray::onScrnShot);

if (!pHK->isRegistered())
hotkeyRegFail.insert(std::make_pair(describe, hotkey));
Expand All @@ -153,17 +140,15 @@ void Tray::initGlobalHotKeys()
onNotificHotkeyRegisteredFail(hotkeyRegFail);
}

void Tray::onSrnShot()
void Tray::onScrnShot()
{
// 第二次就是野指针, 故使用 QPointer 解决 https://blog.csdn.net/luoyayun361/article/details/90199081
if (!m_pSrnShot)
m_pSrnShot = new ScreenShot();
if (!m_scrnShot) m_scrnShot = new ScreenShot();


auto t = sender();
QHotkey* hk = qobject_cast<QHotkey*>(sender());
const auto act = qobject_cast<QAction*>(sender());
if (!hk && !act)
return;
if (!hk && !act) return;

int sst = CaptureHelper::SST_ScrnCapture;
if (hk) {
Expand All @@ -175,22 +160,17 @@ void Tray::onSrnShot()
if (act || sst == CaptureHelper::SST_ScrnCapture
|| sst == CaptureHelper::SST_DelayCapture
|| sst == CaptureHelper::SST_FullScrnCapture)
m_pSrnShot->launchCapture(static_cast<CaptureHelper::CaptureType>(sst));
m_scrnShot->launchCapture(static_cast<CaptureHelper::CaptureType>(sst));
}

void Tray::onPreference(bool checked)
{
Q_UNUSED(checked);

if (!m_pPref) m_pPref = new PrefManage();

m_pPref->setVisible(true);
m_pPref->adjustSize();

#ifdef Q_OS_WIN
// m_pPref->setFixedSize(m_pPref->size());
#endif
if (!m_prefManage) m_prefManage = new PrefManage();

m_prefManage->show();
m_prefManage->resize(680, 360);
}

void Tray::onKeySequenceChanged(const QKeySequence& keySequence)
Expand Down Expand Up @@ -260,10 +240,10 @@ void Tray::onNotificHotkeyRegisteredFail(std::map<const QString, const QString>
void Tray::onActivated(QSystemTrayIcon::ActivationReason reason)
{
if (QSystemTrayIcon::Trigger == reason) { // 鼠标单击
if (!m_pSrnShot)
m_pSrnShot = new ScreenShot();
if (!m_scrnShot)
m_scrnShot = new ScreenShot();

m_pSrnShot->launchCapture(CaptureHelper::SST_ScrnCapture);
m_scrnShot->launchCapture(CaptureHelper::SST_ScrnCapture);
} else {

}
Expand Down
8 changes: 4 additions & 4 deletions src/screen/tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Tray : public QObject
void initGlobalHotKeys();

public slots:
void onSrnShot();
void onScrnShot();
void onPreference(bool checked);
void onKeySequenceChanged(const QKeySequence& keySequence);

Expand All @@ -48,9 +48,9 @@ public slots:
//void onUpdate();

private:
QPointer<ScreenShot> m_pSrnShot; // 前台截图 UI
QPointer<PrefManage> m_pPref; // 偏好设置 UI
QMenu* m_trayIconMenu;
QPointer<ScreenShot> m_scrnShot; // 前台截图 UI
QPointer<PrefManage> m_prefManage; // 偏好设置 UI
QPointer<QMenu> m_trayMenu;
QPointer<QSystemTrayIcon> m_trayIcon;

// hkPtr, "F6", tr("Active Window"), objectName/tupe: SST_ActionWindow
Expand Down
13 changes: 1 addition & 12 deletions src/tool/selectsize/selectsize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "selectsize.h"
#include <QPainter>
#include "../../xglobal.h"
#include "../../screen/drawhelper.h"
#include "../../screen/datamaid.h"

SelectSize::SelectSize(QWidget* parent /*= nullptr*/, Qt::WindowFlags f /*= Qt::WindowFlags()*/)
Expand All @@ -26,9 +25,7 @@ void SelectSize::onTextChanged(QString text)
text = this->text();
QFontMetrics fm(font());
QRect bound = fm.boundingRect(QRect(), Qt::AlignCenter, text);
// qDebug() << "SelectSize::onTextChanged()" << text << " " <<bound << " " << rect();
setFixedSize(bound.size());
// qDebug() <<bound << " " << rect();
resize(bound.size() + QSize(2, 2)); // fix: 1080 和 2K 屏幕下,字体被遮挡
}

void SelectSize::initUI()
Expand All @@ -37,14 +34,6 @@ void SelectSize::initUI()
connect(this, &SelectSize::sigTextChanged, this, &SelectSize::onTextChanged);
}

//void SelectSize::showEvent(QShowEvent *e)
//{
// QWidget::showEvent(e);
// onTextChanged("");

// qDebug() << " rect:" << rect() << " " << this->text();
//}

void SelectSize::paintEvent(QPaintEvent* e)
{
QPainter pa(this);
Expand Down
2 changes: 1 addition & 1 deletion src/tool/selectsize/selectsize.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <QLabel>

// 选中矩形区域的尺寸大小,显示在左上角
// 选中矩形区域的尺寸大小,显示在左上角、尺寸位置的显示
class SelectSize : public QLabel
{
Q_OBJECT
Expand Down

0 comments on commit 482c2dd

Please sign in to comment.