網(wǎng)上有很多關(guān)于pos機菜單鎖,Qt之懸浮球菜單的知識,也有很多人為大家解答關(guān)于pos機菜單鎖的問題,今天pos機之家(www.rcqwhg.com)為大家整理了關(guān)于這方面的知識,讓我們一起來看下吧!
本文目錄一覽:
1、pos機菜單鎖
pos機菜單鎖
一、概述最近想做一個炫酷的懸浮式菜單,考慮到菜單展開和美觀,所以考慮學習下Qt的動畫系統(tǒng)和狀態(tài)機內(nèi)容,打開QtCreator的示例教程瀏覽了下,大致發(fā)現(xiàn)教程中2D Painting程序和Animated Tiles程序有所幫助,如下圖所示,這兩個demo講述了怎么做一個展開動畫,感興趣的同學也可以直接參考
有了這兩個demo之后,就可以開始動工寫咱們自己的程序。
二、效果展示如下兩幅圖就是作者失效的兩個懸浮菜單效果圖,展示圖1代碼已上傳至CSDN,不需要積分即可下載,效果圖2代碼暫時不開源,有需要的朋友可以進一步咨詢
基礎圓形菜單功能,代碼已上傳CSDN - Qt 失效的 PC 端環(huán)形菜單、懸浮球菜單、展開動畫
高級懸浮球菜單、支持二級菜單打開
三、實現(xiàn)代碼實現(xiàn)文件比較簡單,只有頭文件和實現(xiàn)文件,這里先主要放出頭文件,然后講解實現(xiàn)思路,具體實現(xiàn)細節(jié)可以通過下載源碼進行具體了解
1、菜單項PopRingItem為菜單展開項、可以通過綁定外部QAction實現(xiàn)與普通菜單相同功能
class PopRingItem : public QLabel{Q_OBJECTpublic:PopRingItem(QWidget *parent = 0);~PopRingItem();void SetRadius(int radius);int GetRadius() const;void BindAction(QAction * action);signals:void MouseEvent(bool);protected:virtual void enterEvent(QEvent * event) override;virtual void leaveEvent(QEvent * event) override;virtual void paintEvent(QPaintEvent * event) override;protected:int m_iRadius = 50;QAction * m_actAction = nullptr;};2、懸浮球
懸浮球為菜單入口,繼承自菜單項,與菜單項有相似功能
class QVariantAnimation;class QPropertyAnimation;class PopRingMenu : public PopRingItem{Q_OBJECTpublic:PopRingMenu(QWidget *parent = 0);~PopRingMenu();signals:void DoubleClicked();public:void SetActions(const QVector<QAction *> & acts);void SetIcons(const QVector<QString> & icons);void SetAnimationEnabled(bool enabled);bool IsAnimationEnabled() const;void SetSlowlyFade(bool enabled);bool IsSlowlyFade() const;void SetDistanced(int distance);int GetDistanced() const;void SetStartAngle(int angle);int GetStartAngle() const;void SetStepAngle(int angle);int GetStepAngle() const;void SetNormalMenuSize(int size);int GetNormalMenuSize() const;void SetNormalItemSize(int size);int GetNormalItemSize() const;protected:virtual void enterEvent(QEvent * event) override;virtual void leaveEvent(QEvent * event) override;virtual void mouseDoubleClickEvent(QMouseEvent * event) override;virtual void timerEvent(QTimerEvent * event) override;virtual bool event(QEvent * event) override;private slots:void OnMouseEvent(bool);private:void UpdateActions(int msecond);void ExpandMenu();void CollapseMenu();void SlowlyFade();void QuicklyLighter();bool IsUnderMouse() const;void TryCollapseMenu();void KillHideTimer();private:int m_iDistance = 70;int m_iStartAngle = 0;int m_iStepAngle = 60;int m_iMenuSize = 70;int m_iItemSize = 60;int m_iTimerID = -1;QPropertyAnimation * m_pOpacityAnimation = nullptr;QVariantAnimation * m_pItemAnimation = nullptr;QVector<PopRingItem *> m_items;};3、關(guān)鍵點
初始化動畫對象,指定動畫時長和動畫起始、終止值
動畫具體實現(xiàn)函數(shù)未UpdateAction,根據(jù)當前動畫進度值在動畫起始值和終止值所占比例,進行計算當前動畫時刻菜單項的位置和大小
m_pItemAnimation = new QVariantAnimation(this);m_pItemAnimation->setEasingCurve(QEasingCurve::InCubic);m_pItemAnimation->setStartValue(ShowMenuStartValue);m_pItemAnimation->setEndValue(ShowMenuEndValue);m_pItemAnimation->setDuration(ShowMenuDuration);connect(m_pItemAnimation, &QVariantAnimation::valueChanged, this, [this](const QVariant & v){UpdateActions(v.toInt());});
鼠標進入懸浮球時,執(zhí)行展開動畫
void PopRingMenu::ExpandMenu(){if (m_pItemAnimation){if (m_pItemAnimation->state() != QAbstractAnimation::Running&& m_pItemAnimation->currentValue().toInt() != ShowMenuEndValue){m_pItemAnimation->setDirection(QVariantAnimation::Forward);m_pItemAnimation->start();}}else{UpdateActions(ShowMenuEndValue);}KillHideTimer();QuicklyLighter();}
鼠標離開懸浮球時,執(zhí)行收起動畫,與展開動畫相反方向收起動畫時有一個細節(jié)點,那就是鼠標hover在菜單項上時,也不能收起
void PopRingMenu::CollapseMenu(){if (false == IsUnderMouse()){if (m_pItemAnimation){m_pItemAnimation->setDirection(QVariantAnimation::Backward);m_pItemAnimation->start();}else{UpdateActions(ShowMenuStartValue);}KillHideTimer();SlowlyFade();}}
展開和收起動畫實現(xiàn)細節(jié),根據(jù)動畫指定幀數(shù),按比例進行縮放和移動菜單項
void PopRingMenu::UpdateActions(int msecond){int curDistance = msecond * m_iDistance / ShowMenuEndValue;for (int i = 0; i < m_items.size(); ++i){PopRingItem * item = m_items.at(i);double radians = qDegreesToRadians(m_iStepAngle * i * 1.0 + m_iStartAngle);int offx = curDistance * qCos(radians);int offy = curDistance * qSin(radians);item->move(pos() + QPoint(offx, offy));int curSize = msecond * m_iItemSize / ShowMenuEndValue;item->SetRadius(curSize);item->setVisible(ShowMenuStartValue != msecond);};::SetWindowPos(HWND(winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);}
懸浮球指定時間未激活時,淡出,減少對用戶視覺沖擊
void PopRingMenu::SetSlowlyFade(bool enabled){if (enabled){if (nullptr == m_pOpacityAnimation){m_pOpacityAnimation = new QPropertyAnimation(this, "opacity");m_pOpacityAnimation->setEasingCurve(QEasingCurve::OutCubic);m_pOpacityAnimation->setStartValue(SlowlyStartValue);m_pOpacityAnimation->setEndValue(SlowLyEndValue);m_pOpacityAnimation->setDuration(SlowlyFadeDuration);}}else{if (m_pOpacityAnimation){delete m_pOpacityAnimation;m_pOpacityAnimation = nullptr;}}}
以上就是關(guān)于pos機菜單鎖,Qt之懸浮球菜單的知識,后面我們會繼續(xù)為大家整理關(guān)于pos機菜單鎖的知識,希望能夠幫助到大家!