115 lines
3.0 KiB
C++
115 lines
3.0 KiB
C++
|
|
#include "InputModeMenu.h"
|
||
|
|
#include "ui_InputModeMenu.h"
|
||
|
|
|
||
|
|
#include <QListWidget>
|
||
|
|
#include <QResizeEvent>
|
||
|
|
#include <QPainter>
|
||
|
|
|
||
|
|
namespace
|
||
|
|
{
|
||
|
|
const QStringList INPUT_MODE_LIST = QStringList() << "En" << "PinYin" << "HandWrite";
|
||
|
|
const QSize MENU_SIZE = QSize(143,148);
|
||
|
|
const int TRIANGLE_WIDTH = 10;
|
||
|
|
const int TRIANGLE_HEIGHT = 10;
|
||
|
|
const int TRIANGLE_WIDTHOFFSEt = -50;
|
||
|
|
}
|
||
|
|
|
||
|
|
InputModeMenu::InputModeMenu(QWidget *aParent)
|
||
|
|
: QWidget(aParent)
|
||
|
|
, mMenuList(new QListWidget(this))
|
||
|
|
{
|
||
|
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
||
|
|
setGeometry(0,0,MENU_SIZE.width(),MENU_SIZE.height());
|
||
|
|
connect(mMenuList,&QListWidget::itemClicked,this,&InputModeMenu::switchInputMode);
|
||
|
|
initializeInputModeList();
|
||
|
|
setWindowFlags( Qt::FramelessWindowHint |Qt::WindowStaysOnTopHint | Qt::Tool | Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint);
|
||
|
|
}
|
||
|
|
|
||
|
|
InputModeMenu::~InputModeMenu()
|
||
|
|
{
|
||
|
|
delete mMenuList;
|
||
|
|
}
|
||
|
|
|
||
|
|
void InputModeMenu::initializeInputModeList()
|
||
|
|
{
|
||
|
|
mMenuList->addItems(INPUT_MODE_LIST);
|
||
|
|
}
|
||
|
|
|
||
|
|
void InputModeMenu::resizeEvent(QResizeEvent *aEvent)
|
||
|
|
{
|
||
|
|
if (nullptr == aEvent)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
QSize size = aEvent->size();
|
||
|
|
mMenuList->setGeometry(5,5,size.width()-10,size.height()-20);
|
||
|
|
|
||
|
|
for(int i=0;i<mMenuList->count();++i)
|
||
|
|
{
|
||
|
|
mMenuList->item(i)->setSizeHint(QSize(mMenuList->size().width()-2,mMenuList->size().height()/INPUT_MODE_LIST.count() -2));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void InputModeMenu::paintEvent(QPaintEvent *aEvent)
|
||
|
|
{
|
||
|
|
QPainter painter(this);
|
||
|
|
QLinearGradient linearGradient(0.5, 0, 0.5, 1);
|
||
|
|
linearGradient.setColorAt(0, "#f7f7f7");
|
||
|
|
linearGradient.setColorAt(1, "#ffffff");
|
||
|
|
|
||
|
|
QBrush brush(linearGradient);
|
||
|
|
painter.setBrush(brush);
|
||
|
|
painter.setPen(Qt::NoPen);
|
||
|
|
|
||
|
|
QRect rect = geometry();
|
||
|
|
int w = rect.width();
|
||
|
|
int h = rect.height();
|
||
|
|
|
||
|
|
QPolygon triangle;
|
||
|
|
triangle.setPoints(3,w/2+TRIANGLE_WIDTHOFFSEt,h-1,w/2-TRIANGLE_WIDTH+TRIANGLE_WIDTHOFFSEt,h-TRIANGLE_HEIGHT,w/2+TRIANGLE_WIDTH+TRIANGLE_WIDTHOFFSEt,h-TRIANGLE_HEIGHT);
|
||
|
|
painter.drawRoundedRect(0,0,w-1,h-TRIANGLE_HEIGHT,5,5);
|
||
|
|
painter.drawPolygon(triangle);
|
||
|
|
|
||
|
|
QWidget::paintEvent(aEvent);
|
||
|
|
}
|
||
|
|
|
||
|
|
void InputModeMenu::setCurrentInputMode(InputMode aInputMode)
|
||
|
|
{
|
||
|
|
switch (aInputMode)
|
||
|
|
{
|
||
|
|
case InputMode::LowMode:
|
||
|
|
mMenuList->setCurrentRow(0);
|
||
|
|
break;
|
||
|
|
case InputMode::ChineseMode:
|
||
|
|
mMenuList->setCurrentRow(1);
|
||
|
|
break;
|
||
|
|
case InputMode::HandWriteMode:
|
||
|
|
mMenuList->setCurrentRow(2);
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
mMenuList->setCurrentRow(0);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void InputModeMenu::switchInputMode(QListWidgetItem* aItem)
|
||
|
|
{
|
||
|
|
if (nullptr == aItem)
|
||
|
|
{
|
||
|
|
return ;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ( INPUT_MODE_LIST.at(0) == aItem->text())
|
||
|
|
{
|
||
|
|
emit inputModeSelected(InputMode::LowMode);
|
||
|
|
}
|
||
|
|
else if(INPUT_MODE_LIST.at(1) == aItem->text())
|
||
|
|
{
|
||
|
|
emit inputModeSelected(InputMode::ChineseMode);
|
||
|
|
}
|
||
|
|
else if(INPUT_MODE_LIST.at(2) == aItem->text())
|
||
|
|
{
|
||
|
|
emit inputModeSelected(InputMode::HandWriteMode);
|
||
|
|
}
|
||
|
|
}
|