#include #include #include "mconfig.h" #include "widget.h" #include extern "C" { #include "../Lua/src/lua.h" #include "../Lua/src/lualib.h" #include "../Lua/src/lauxlib.h" } /// ÇÏ´Ü Ä«ÇǶóÀÌÆ® ÅؽºÆ®. static const wchar_t *comment = L"ÀÌ ÇÁ·Î±×·¥Àº ¸¶ºñ³ë±â ŸÀÓÁî(http://www.mabinogi.pe.kr)ÀÇ Á¤º¸¸¦ ¹ÙÅÁÀ¸·Î Á¦ÀÛÇÏ¿´½À´Ï´Ù."; /// Ç÷¹Å¸ÀÇ µîÀå ½Ã°£ Ç¥½Ã ÅؽºÆ®. static const wchar_t *fletaTime = L"¿¡¸°½Ã°¢ 09:00 ~ 11:00, 15:00 ~ 17:00, 19:00 ~ 21:00"; /// Ç÷¹Å¸ÀÇ µîÀå À§Ä¡ Ç¥½Ã ÅؽºÆ®. static const wchar_t *fletaLocation = L"À§Ä¡: ¼¾¸¶ÀÌ Æò¿ø Áß¾Ó »ï°Å¸® ±Ùó"; /** * ºÐ´ÜÀ§¸¦ ºÐ:ÃÊ Çü½ÄÀÇ ÅؽºÆ®·Î º¯È¯. * @return ½Ã°£:ºÐ Çü½ÄÀÇ ÅؽºÆ® Æ÷¸ËÀ¸·Î º¯È¯ µÈ °ª. */ static QString sec2MinSec(uint mins) { QString result; uint hrs = mins / 60; uint min = mins % 60; result.sprintf("%02d:%02d", hrs, min); return result; } static uint time2Sec(uint mins, uint secs) { return mins * 60 + secs; } /** * Lua ½ºÅ©¸³Æ®ÀÇ Æ¯Á¤ º¯¼ö °ªÀ» QList Çü½ÄÀÇ °´Ã¼·Î º¯È¯ ÇÑ´Ù. * @param state ¸®½ºÆ® °´Ã¼·Î º¯È¯ ÇÒ LuaÀÇ State. * @param name ¸®½ºÆ® °´Ã¼·Î º¯È¯ µÉ Àü¿ª º¯¼ö À̸§. * @param codec Lua ½ºÅ©¸³Æ®ÀÇ ¹®ÀÚ ÀÎÄÚµùÀ» QString·Î º¯È¯ ÇÒ ¶§ ¾²ÀÏ °´Ã¼. * @param strings Lua ½ºÅ©¸³Æ®¿¡¼­ »ÌÀº ¹è¿­ º¯¼ö°¡ ÀúÀå µÉ °´Ã¼. */ static void luaStringTableToList(lua_State *state, char *name, QTextCodec *codec, QList &strings) { // http://blog.naver.com/fantajeon/80005019590 lua_pushstring(state, name); lua_rawget(state, LUA_GLOBALSINDEX); lua_pushnil(state); while(lua_next(state, -2) != 0) { //lua_tointeger(state, -2); // index //lua_tostring(state, -1)); // value strings.push_back(codec->toUnicode(lua_tostring(state, -1))); lua_pop(state, 1); } lua_pop(state, 1); } static void luaArbeitTableToList(lua_State *state, char *name, QTextCodec *codec, QList &strings) { Arbeit arbeit; lua_pushstring(state, name); lua_rawget(state, LUA_GLOBALSINDEX); lua_pushnil(state); while(lua_next(state, -2) != 0) { lua_pushstring(state, "n"); // after value is -2 lua_gettable(state, -2); arbeit.name = codec->toUnicode(lua_tostring(state, -1)); lua_pop(state, 1); lua_pushstring(state, "s"); lua_gettable(state, -2); arbeit.begin = (int)lua_tointeger(state, -1); lua_pop(state, 1); lua_pushstring(state, "e"); lua_gettable(state, -2); arbeit.end = (int)lua_tointeger(state, -1); lua_pop(state, 1); strings.push_back(arbeit); lua_pop(state, 1); } lua_pop(state, 1); } inline int weatherTypeToInt(CMabiWeather::EWeatherType type) { switch(type) { case CMabiWeather::EWT_STORM: return 3; case CMabiWeather::EWT_RAIN: return 2; case CMabiWeather::EWT_CLOUD: return 1; case CMabiWeather::EWT_CLEAR: return 0; } return 0; } inline int compareWeather(CMabiWeather::EWeatherType a, CMabiWeather::EWeatherType b) { return weatherTypeToInt(a) - weatherTypeToInt(b); } inline QString toWeatherString(CMabiWeather::EWeatherType type) { switch(type) { case CMabiWeather::EWT_STORM: return QString::fromWCharArray(L"õµÕ"); break; case CMabiWeather::EWT_RAIN: return QString::fromWCharArray(L"ºñ¿È"); break; case CMabiWeather::EWT_CLOUD: return QString::fromWCharArray(L"È帲"); break; case CMabiWeather::EWT_CLEAR: return QString::fromWCharArray(L"¸¼À½"); break; default: return "INF"; } } time_t findBeginWeather(CMabiWeather *weather, CMabiWeather::EWeatherType wantType, time_t current) { const int step = 60 * 20; float weatherValue; CMabiWeather::EWeatherType weatherType; current = current - (current % step); weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); if(compareWeather(weatherType, wantType) == 0) { do { current = current - step; weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); } while(compareWeather(weatherType, wantType) == 0); current = current + step; } else if(compareWeather(weatherType, wantType) > 0) { do { current = current - step; weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); } while(compareWeather(weatherType, wantType) < 0); current = current + step; } else { do { current = current + step; weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); } while(compareWeather(weatherType, wantType) < 0); } return current; } time_t findEndWeather(CMabiWeather *weather, CMabiWeather::EWeatherType wantType, time_t current) { const int step = 60 * 20; float weatherValue; CMabiWeather::EWeatherType weatherType; current = current - (current % step); weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); if(compareWeather(weatherType, wantType) == 0) { do { current = current + step; weatherValue = weather->getWeather(current); weatherType = weather->getType(weatherValue); } while(compareWeather(weatherType, wantType) == 0); } return current; } Widget::Widget(QWidget *parent) : QWidget(parent) { weatherCurrent = 1; glass = new Glass; weather = new CMabiWeather(weatherCurrent); alert = new AlertWidget(); alert->show(); alert->setRadius(3); alert->setFont(QFont("Gulim", 26)); alert->setColor(QColor(Qt::white), QColor(Qt::black)); isInitialized = true; isFirstTransparent = true; initWeather(); initSequence(); createLayout(); createLable(); createOption(); createTrayicon(); // final setLayout(mainLayout); mainLayout->setSizeConstraint(QLayout::SetFixedSize); mainLayout->setMargin(15); setWindowIcon(QIcon(glass->GetAppIconPixmap(winId()))); setWindowTitle(QString::fromWCharArray(L"¸¶ºñ ŸÀÌ¸Ó v"_U_VERSION_)); setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground, true); background.load(":/background.png"); QPalette palette = this->palette(); QColor color = Qt::white; color.setAlpha(0); palette.setColor(QPalette::Button, color); btClose->setPalette(palette); cbArbeit->setPalette(palette); cbWeather->setPalette(palette); timer.start(500, this); } Widget::~Widget() { delete glass; delete weather; } bool Widget::initialized() { return isInitialized; } void Widget::initWeather() { if(QFile::exists("weathercommon.xml")) { weatherArea.append(QString::fromWCharArray(L"Ƽ¸£ ÄÚ³×ÀÏ, µÎ°¥µå ¾ÆÀÏ")); weatherArea.append(QString::fromWCharArray(L"´ø¹ÙÆ°, °¡ÀÌ·¹Èå")); weatherArea.append(QString::fromWCharArray(L"¹ÝÈ£¸£")); weatherArea.append(QString::fromWCharArray(L"ÀÌ¸à ¸¶ÇÏ")); weatherArea.append(QString::fromWCharArray(L"¼¾¸¶ÀÌ Æò¿ø")); weatherArea.append(QString::fromWCharArray(L"ÄÉ¾È Ç×±¸")); weatherArea.append(QString::fromWCharArray(L"¶ó³ë Áö¿ª")); weatherArea.append(QString::fromWCharArray(L"ÄÜ´©½º Áö¿ª")); weatherArea.append(QString::fromWCharArray(L"Äí¸£Å¬·¹ Áö¿ª")); weatherArea.append(QString::fromWCharArray(L"ÀÚ¸£µò Áö¿ª")); weatherArea.append(QString::fromWCharArray(L"±×¸²ÀÚ ¼¼°è")); weatherArea.append(QString::fromWCharArray(L"Żƾ, Ÿ¶ó")); } else { wchar_t message[] = L"³¯¾¾ÆÄÀÏ[weathercommon.xml]ÀÌ ¾ø½À´Ï´Ù.\nÇÁ·Î±×·¥À» ½ÇÇà ÇÒ ¼ö ¾ø½À´Ï´Ù."; QMessageBox::critical( this, QString::fromWCharArray(L"¿À·ù"), QString::fromWCharArray(message), QMessageBox::Ok, QMessageBox::Ok); isInitialized = false; } } void Widget::initSequence() { lua_State *state = luaL_newstate(); try { if(luaL_loadfile(state, "Sequence.lua") || lua_pcall(state, 0, 0, 0)) { throw L"¼³Á¤ÆÄÀÏ[Sequence.lua]ÀÌ À߸ø µÇ¾ú½À´Ï´Ù.\nÇÁ·Î±×·¥À» ½ÇÇà ÇÒ ¼ö ¾ø½À´Ï´Ù."; } else { QTextCodec *codec; lua_getglobal(state, "encoding"); codec = QTextCodec::codecForName(lua_tostring(state, -1)); lua_pop(state, 1); if(codec == NULL) { throw L"¼³Á¤ÆÄÀÏ[Sequence.lua]¿¡¼­ encoding¸¦ ãÀ» ¼ö ¾ø°Å³ª ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù."; } luaStringTableToList(state, "moongateSequence", codec, moongateSequence); luaArbeitTableToList(state, "arbeitSequence", codec, arbeitSequence); luaStringTableToList(state, "weekdayEffectsName", codec, weekdayEffectsName); luaStringTableToList(state, "weekdayEffectsContent", codec, weekdayEffectsContent); luaStringTableToList(state, "weekdayEffectsAdvance", codec, weekdayEffectsAdvance); luaStringTableToList(state, "priceSequence", codec, priceSequence); if( moongateSequence.size() < 1 || arbeitSequence.size() < 1 || weekdayEffectsName.size() < 1 || weekdayEffectsContent.size() < 1 || weekdayEffectsAdvance.size() < 1 || priceSequence.size() < 1) { throw L"¼³Á¤ÆÄÀÏ[Sequence.lua]ÀÇ ³»¿ëÀÌ ´©¶ô µÇ¾ú½À´Ï´Ù.\nÇÁ·Î±×·¥À» ½ÇÇà ÇÒ ¼ö ¾ø½À´Ï´Ù."; } } } catch(wchar_t* message) { QMessageBox::critical( this, QString::fromWCharArray(L"¿À·ù"), QString::fromWCharArray(message), QMessageBox::Ok, QMessageBox::Ok); isInitialized = false; } lua_close(state); } void Widget::initAlerts() { } void Widget::createLayout() { QLabel *lbComment; lbComment = new QLabel(QString::fromWCharArray(comment)); lbComment->setWordWrap(true); mainLayout = new QGridLayout; mainLayout->setVerticalSpacing(10); // static label mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"¿¡¸°½Ã°£:")), 0, 0, Qt::AlignTop); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"¹®°ÔÀÌÆ®:")), 1, 0, Qt::AlignTop); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"¾Æ¸£¹ÙÀÌÆ®:")), 2, 0, Qt::AlignVCenter); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"³¯¾¾:")), 3, 0, Qt::AlignVCenter); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"¿äÀÏÈ¿°ú:")), 5, 0, Qt::AlignTop); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"¾îµå¹ê½ºµå ¾ÆÀÌÅÛ:")), 6, 0, 1, -1, Qt::AlignTop); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"ÇÁ¶óÀ̽º:")), 8, 0, Qt::AlignTop); mainLayout->addWidget(new QLabel(QString::fromWCharArray(L"Ç÷¹Å¸:")), 9, 0, Qt::AlignTop); mainLayout->addWidget(lbComment, 10, 0, 1, -1, Qt::AlignTop); // time timeLayout = new QHBoxLayout; timeLayout->addWidget(new QLabel(QString::fromWCharArray(L"Çö½Ç½Ã°£:")), 0, Qt::AlignTop); mainLayout->addLayout(timeLayout, 0, 1, 1, 1, Qt::AlignTop); // gate gateLayout = new QVBoxLayout; mainLayout->addLayout(gateLayout, 1, 1, 1, 1, Qt::AlignTop); // arbeit arbeitLayout = new QHBoxLayout; mainLayout->addLayout(arbeitLayout, 2, 1, 1, -1, Qt::AlignVCenter); // weather weatherLayout = new QHBoxLayout; mainLayout->addLayout(weatherLayout, 3, 1, 1, -1, Qt::AlignVCenter); // weekeffect effectLayout = new QVBoxLayout; mainLayout->addLayout(effectLayout, 5, 1, 1, -1, Qt::AlignTop); // price priceLayout = new QVBoxLayout; mainLayout->addLayout(priceLayout, 8, 1, 1, -1, Qt::AlignTop); // fleta fletaLayout = new QVBoxLayout; mainLayout->addLayout(fletaLayout, 9, 1, 1, -1, Qt::AlignTop); // options optionLayout = new QHBoxLayout; mainLayout->addLayout(optionLayout, 11, 0, 1, -1, Qt::AlignTop); // close button QImage close(":/close.png"); btClose = new QToolButton; btClose->setIcon(QPixmap::fromImage(close)); btClose->setIconSize(close.size() + QSize(5, 5)); //btClose->setContentsMargins(0, 0, 0, 0); mainLayout->addWidget(btClose, 0, 2, 2, 1, Qt::AlignTop | Qt::AlignRight); connect(btClose, SIGNAL(clicked()), this, SLOT(closeTimer())); } void Widget::createLable() { QString loading(QString::fromWCharArray(L"loading...")); // dynamic label // time lbRealTime = new QLabel(loading); lbErinnTime = new QLabel(loading); timeLayout->addWidget(lbRealTime, 0, Qt::AlignTop); timeLayout->insertWidget(0, lbErinnTime, 0, Qt::AlignTop); timeLayout->addStretch(); timeLayout->setSpacing(15); // gate lbMoongate = new QLabel(loading); lbMoongateNext = new QLabel(loading); gateLayout->addWidget(lbMoongate); gateLayout->addWidget(lbMoongateNext); //gateLayout->addStretch(); gateLayout->setSpacing(2); // arbeit lbArbeit = new QLabel(loading); cbArbeit = new QComboBox; for(int i = 0; i < arbeitSequence.size(); i++) { cbArbeit->addItem(arbeitSequence[i].name); } arbeitLayout->addWidget(cbArbeit, 0, Qt::AlignVCenter); arbeitLayout->addWidget(lbArbeit, 0, Qt::AlignVCenter); arbeitLayout->setSpacing(15); // weather lbWeather = new QLabel(loading); cbWeather = new QComboBox; for(int i = 0; i < weatherArea.size(); i++) { cbWeather->addItem(weatherArea[i]); } weatherLayout->addWidget(cbWeather, 0, Qt::AlignVCenter); weatherLayout->setSpacing(2); mainLayout->addWidget(lbWeather, 4, 1, 1, -1, Qt::AlignVCenter); // weekeffect lbWeekEffectName = new QLabel(loading); lbWeekEffectContent = new QLabel(loading); effectLayout->addWidget(lbWeekEffectName); effectLayout->addWidget(lbWeekEffectContent); //effectLayout->addStretch(); effectLayout->setSpacing(10); lbWeekAdvanceItem = new QLabel(loading); mainLayout->addWidget(lbWeekAdvanceItem, 7, 1, Qt::AlignTop); // price lbPrice = new QLabel(loading); lbPriceNext1 = new QLabel(loading); lbPriceNext2 = new QLabel(loading); priceLayout->addWidget(lbPrice); priceLayout->addWidget(lbPriceNext1); priceLayout->addWidget(lbPriceNext2); //priceLayout->addStretch(); priceLayout->setSpacing(2); // fleta fletaLayout->addWidget(new QLabel(QString::fromWCharArray(fletaTime))); fletaLayout->addWidget(new QLabel(QString::fromWCharArray(fletaLocation))); fletaLayout->addStretch(); fletaLayout->setSpacing(2); } void Widget::createOption() { // options cbTopmost = new QCheckBox(QString::fromWCharArray(L"Ç×»ó À§")); slOpacity = new QSlider(Qt::Horizontal); slOpacity->setMinimum(20); slOpacity->setMaximum(100); slOpacity->setValue(100); optionLayout->addWidget(cbTopmost); optionLayout->addWidget(slOpacity, Qt::AlignRight); optionLayout->addStretch(); optionLayout->setSpacing(15); connect(cbTopmost, SIGNAL(clicked()), this, SLOT(toggleTopmost())); connect(slOpacity, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity(int))); } void Widget::createTrayicon() { // action showAction = new QAction(QString::fromWCharArray(L"ŸÀÌ¸Ó º¸À̱â(&S)"), this); transWindow = new QAction(QString::fromWCharArray(L"Åõ¸í À©µµ¿ì(&T)"), this); quitQction = new QAction(QString::fromWCharArray(L"Á¾·á(&X)"), this); showAction->font().setWeight(QFont::Bold); transWindow->setCheckable(true); connect(showAction, SIGNAL(triggered()), this, SLOT(showTimer())); connect(transWindow, SIGNAL(triggered()), this, SLOT(toggleTransparent())); connect(quitQction, SIGNAL(triggered()), this, SLOT(closeTimer())); // tray icon trayMenu = new QMenu(this); trayMenu->addAction(showAction); trayMenu->addAction(transWindow); trayMenu->addSeparator(); trayMenu->addAction(quitQction); trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayMenu); trayIcon->setIcon(QIcon(glass->GetTrayIconPixmap(winId()))); trayIcon->show(); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); } void Widget::update() { updateTime(); updateMoongate(); updateArbeit(); updateWeather(); updateWeekEffect(); updatePrice(); updateAlert(); if(size() != mainLayout->sizeHint()) { resize(mainLayout->sizeHint()); } } void Widget::updateTime() { QDateTime midnight; realTime = QDateTime::currentDateTime(); midnight.setDate(realTime.date()); erinnTime.setTime_t((realTime.toTime_t() - midnight.toTime_t()) % 2160); QTime time = realTime.time(); lbRealTime->setText(sec2MinSec(time.hour() * 60 + time.minute())); lbErinnTime->setText(sec2MinSec(erinnTime.toTime_t() * 2 / 3)); } void Widget::updateMoongate() { int size = moongateSequence.size(); int midx0 = ((int)((realTime.toTime_t() - 540 - 60) / 2160)) % size; int midx1 = (midx0 + 1) % size; int midx2 = (midx1 + 1) % size; QString gateWait(moongateSequence[midx0]); if((erinnTime.toTime_t() > 546) && (erinnTime.toTime_t() <= 1626)) { gateWait.append(QString::fromWCharArray(L" - ´ë±â (")); gateWait.append(sec2MinSec(1626 - erinnTime.toTime_t())); gateWait.append(QString::fromWCharArray(L" ÈÄ ¿­¸²)")); } else { int waitTime = 546 - erinnTime.toTime_t(); if(waitTime < 0) { waitTime = waitTime + 2160; } gateWait.append(QString::fromWCharArray(L" - ¿­¸² (")); gateWait.append(sec2MinSec(waitTime)); gateWait.append(QString::fromWCharArray(L" ÈÄ ´ÝÈû)")); } QString gateNext; gateNext.append(QString::fromWCharArray(L" ¡æ ")); gateNext.append(moongateSequence[midx1]); gateNext.append(QString::fromWCharArray(L" ¡æ ")); gateNext.append(moongateSequence[midx2]); lbMoongate->setText(gateWait); lbMoongateNext->setText(gateNext); } void Widget::updateArbeit() { int idx = cbArbeit->currentIndex(); int count = arbeitSequence.size(); if(idx < 0 || idx >= count) { lbArbeit->setText(QString(QString::fromWCharArray(L"out of range"))); } else { const Arbeit& arbeit = arbeitSequence[idx]; QString message; if((erinnTime.toTime_t() > (uint)arbeit.begin) && (erinnTime.toTime_t() <= (uint)arbeit.end)) { message.append(QString(QString::fromWCharArray(L"ÁøÇà Áß ("))); message.append(sec2MinSec(arbeit.end - erinnTime.toTime_t())); message.append(QString(QString::fromWCharArray(L" ÈÄ Á¾·á)"))); } else { int waitTime = arbeit.begin - erinnTime.toTime_t(); if(waitTime < 0) { waitTime = waitTime + 2160; } message.append(QString(QString::fromWCharArray(L"´ë±â Áß ("))); message.append(sec2MinSec(waitTime)); message.append(QString(QString::fromWCharArray(L" ÈÄ ½ÃÀÛ)"))); } lbArbeit->setText(message); } } void Widget::updateWeather() { if(weatherCurrent != cbWeather->currentIndex() + 1) { delete weather; weatherCurrent = cbWeather->currentIndex() + 1; weather = new CMabiWeather(weatherCurrent); } time_t nowTime = time(NULL); time_t rainTime = findBeginWeather(weather, CMabiWeather::EWT_RAIN, nowTime); time_t stormTime = findBeginWeather(weather, CMabiWeather::EWT_STORM, nowTime); float weatherValue = weather->getWeather(nowTime); float rainAmount = floorf(weather->getRainAmount(weatherValue) * 20); time_t weatherEndTime = findEndWeather(weather, weather->getType(weatherValue), nowTime); QDateTime rainDateTime = QDateTime::fromTime_t(rainTime); QDateTime stormDateTime = QDateTime::fromTime_t(stormTime); QDateTime endDateTime = QDateTime::fromTime_t(weatherEndTime - nowTime); QString weatherString; endDateTime = endDateTime.toUTC(); weatherString.append(QString::fromWCharArray(L"ÇöÀç ³¯¾¾: ")); weatherString.append(toWeatherString(weather->getType(weatherValue))); if(rainAmount > 0) { weatherString.append(" (+"); weatherString.append(QString::number(rainAmount)); weatherString.append(")"); } weatherValue = weather->getWeather(weatherEndTime); rainAmount = floorf(weather->getRainAmount(weatherValue) * 20); weatherString.append(" ("); weatherString.append(endDateTime.toString(QString::fromWCharArray(L"hh:mm:ss ÈÄ "))); weatherString.append(toWeatherString(weather->getType(weatherValue))); if(rainAmount > 0) { weatherString.append(" (+"); weatherString.append(QString::number(rainAmount)); weatherString.append(")"); } weatherString.append(")"); weatherValue = weather->getWeather(rainTime); rainAmount = floorf(weather->getRainAmount(weatherValue) * 20); weatherString.append(QString::fromWCharArray(L"\nºñ¿Ã ³¯Â¥: ")); weatherString.append(rainDateTime.toString("MM/dd hh:mm:ss")); if(rainAmount > 0) { weatherString.append(" (+"); weatherString.append(QString::number(rainAmount)); weatherString.append(")"); } weatherString.append(QString::fromWCharArray(L"\nõµÕ ¿¹Á¤: ")); weatherString.append(stormDateTime.toString("MM/dd hh:mm:ss")); lbWeather->setText(weatherString); } void Widget::updateWeekEffect() { int idx = realTime.date().dayOfWeek() % 7; lbWeekEffectName->setText(weekdayEffectsName[idx]); lbWeekEffectContent->setText(weekdayEffectsContent[idx]); lbWeekAdvanceItem->setText(weekdayEffectsAdvance[idx]); } void Widget::updatePrice() { int count = priceSequence.size(); int pidx0 = ((int)(realTime.toTime_t() / 2160)) % count; int pidx1 = (pidx0 + 1) % count; int pidx2 = (pidx1 + 1) % count; QString message1(priceSequence[pidx0]); QString message2(QString::fromWCharArray(L"¡æ ")); QString message3(QString::fromWCharArray(L"¡æ ")); message1.append(QString::fromWCharArray(L" - ")); message1.append(sec2MinSec(2160 - erinnTime.toTime_t())); message1.append(QString::fromWCharArray(L" ÈÄ À̵¿")); message2.append(priceSequence[pidx1]); message3.append(priceSequence[pidx2]); lbPrice->setText(message1); lbPriceNext1->setText(message2); lbPriceNext2->setText(message3); } void Widget::updateAlert() { uint secs = erinnTime.toTime_t() * 2 / 3; if(secs == time2Sec(5, 30)) { alert->setMessage(QString::fromWCharArray(L"º¯½Å½Ã°£ 30ºÐ ÀüÀÔ´Ï´Ù.")); } if(secs == time2Sec(5, 50)) { alert->setMessage(QString::fromWCharArray(L"º¯½Å½Ã°£ 10ºÐ ÀüÀÔ´Ï´Ù.")); } } void Widget::showTimer() { show(); activateWindow(); } void Widget::closeTimer() { close(); } void Widget::toggleTransparent() { show(); if(isFirstTransparent) { QMessageBox::information( this, QString::fromWCharArray(L"È®ÀÎ"), QString::fromWCharArray(L"¸¶¿ì½º µ¿ÀÛÀ» ¹«½ÃÇÏ´Â Åõ¸í À©µµ¿ì ¸ðµå·Î ½ÇÇàÇÕ´Ï´Ù.\nÆ®·¹ÀÌ ¸Þ´º¿¡¼­ 'Åõ¸í À©µµ¿ì' Ç׸ñÀ» ´Ù½Ã ¼±Åà ÇϽøé ÇØÁ¦µË´Ï´Ù."), QMessageBox::Ok, QMessageBox::Ok); isFirstTransparent = false; } glass->SetTransparent(winId(), cbTopmost->isChecked(), transWindow->isChecked()); } void Widget::toggleTopmost() { #ifdef _WIN32 glass->SetTopmost(winId(), cbTopmost->isChecked()); #else Qt::WindowFlags flags = windowFlags(); if(cbTopmost->isChecked()) { flags = flags | Qt::WindowStaysOnTopHint; } else { flags = flags & ~Qt::WindowStaysOnTopHint; } setWindowFlags(flags); show(); activateWindow(); #endif } void Widget::changeOpacity(int opacity) { setWindowOpacity(((qreal)opacity) / 100); } void Widget::trayActivated(QSystemTrayIcon::ActivationReason reason) { if(reason == QSystemTrayIcon::DoubleClick) { show(); activateWindow(); } else if(reason == QSystemTrayIcon::Trigger) { activateWindow(); } } void Widget::paintEvent(QPaintEvent *) { QPainter painter(this); int mWidth = width(); int mHeight = height(); int iWidth = background.width(); int iHeight = background.height(); // corner painter.drawImage(QRectF(0, 0, 10, 10), background, QRectF(0, 0, 10, 10)); painter.drawImage(QRectF(mWidth - 10, 0, 10, 10), background, QRectF(iWidth - 10, 0, 10, 10)); painter.drawImage(QRectF(mWidth - 10, mHeight - 10, 10, 10), background, QRectF(iWidth - 10, iHeight - 10, 10, 10)); painter.drawImage(QRectF(0, mHeight - 10, 10, 10), background, QRectF(0, iHeight - 10, 10, 10)); // side painter.drawImage(QRectF(10, 0, mWidth - 20, 10), background, QRectF(10, 0, iWidth - 20, 10)); painter.drawImage(QRectF(mWidth - 10, 10, 10, mHeight - 20), background, QRectF(iWidth - 10, 10, 10, iHeight - 20)); painter.drawImage(QRectF(10, mHeight - 10, mWidth - 20, 10), background, QRectF(10, iHeight - 10, iWidth - 20, 10)); painter.drawImage(QRectF(0, 10, 10, mHeight - 20), background, QRectF(0, 10, 10, iHeight - 20)); // inner painter.drawImage(QRectF(10, 10, mWidth - 20, mHeight - 20), background, QRectF(10, 10, iWidth - 20, iHeight - 20)); } void Widget::timerEvent(QTimerEvent *) { update(); } void Widget::closeEvent(QCloseEvent *event) { QMessageBox::StandardButton result; if(isVisible()) { result = QMessageBox::question( this, QString::fromWCharArray(L"È®ÀÎ"), QString::fromWCharArray(L"ÇÁ·Î±×·¥À» Á¾·á ÇϽðڽÀ´Ï±î?\n¾Æ´Ï¿À¸¦ ÇϽøé Æ®·¹ÀÌ ¾ÆÀÌÄÜÀ¸·Î ÃÖ¼ÒÈ­ µË´Ï´Ù."), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel); } else { result = QMessageBox::question( this, QString::fromWCharArray(L"È®ÀÎ"), QString::fromWCharArray(L"ÇÁ·Î±×·¥À» Á¾·á ÇϽðڽÀ´Ï±î?"), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); } if(result == QMessageBox::No) { hide(); event->ignore(); trayIcon->showMessage( QString::fromWCharArray(L"¸¶ºñ³ë±â ŸÀ̸Ó"), QString::fromWCharArray(L"Æ®·¹ÀÌ ¾ÆÀÌÄÜÀ¸·Î ½ÇÇà ÁßÀÔ´Ï´Ù.\n¾ÆÀÌÄÜÀ» ´õºíŬ¸¯ ÇÏ¿© âÀ» ´Ù½Ã º¸ÀÏ ¼ö ÀÖ½À´Ï´Ù.\n¿ìŬ¸¯ ÇÏ½Ã¸é ¸Þ´º Ç׸ñÀÌ ºÒ·¯Áý´Ï´Ù."), QSystemTrayIcon::Information, 3000); } else if(result == QMessageBox::Cancel) { show(); event->ignore(); } } void Widget::mouseMoveEvent(QMouseEvent *event) { if(event->buttons() & Qt::LeftButton) { move(event->globalPos() - dragPos); event->accept(); } } void Widget::mousePressEvent(QMouseEvent *event) { if(event->buttons() & Qt::LeftButton) { dragPos = event->globalPos() - frameGeometry().topLeft(); event->accept(); } }