Пример #1
0
void TweaksPlugin::patchReadingLife()
{
    LOG_TRACE(l);
    FooterLabelWidget *readingLife = qApp->activeWindow()->findChild<FooterLabelWidget *>("readingLife");
    if(readingLife)
    {
        ReadingLifeMenuController* fbmc = readingLife->findChildren<ReadingLifeMenuController *>().last();
        NickelTouchMenu *ntm = readingLife->findChildren<NickelTouchMenu *>().last();

        if (fbmc && ntm)
        {
            // Clear menu and add entries based on configuration
            static QPoint origPos = ntm->pos();
            static int elemHeight = ntm->sizeHint().height()/2;

            ntm->clear();

            QList<MenuEntry>::iterator it;
            int activeEntries = 0;
            for(it = menuEntries.begin(); it != menuEntries.end(); it++) {
                if (it->enabled()) {
                    MenuTextItem *mti = NULL;
                    mti = fbmc->createMenuTextItem(ntm, it->name(), false, false);
                    mti->setSelected(false);
                    fbmc->addWidgetActionWithMapper(ntm, mti, &mapper, it->action(), true, true);
                    ntm->addSeparator();
                    activeEntries++;
                }
            }

            pluginSettings->beginGroup("CustomCommands");
            QStringList keys = pluginSettings->allKeys();

            QList<QString>::iterator keyit;
            for(keyit = keys.begin(); keyit != keys.end(); keyit++) {
                LOG_DEBUG(l) << "custom command: " << keyit->toStdString();
                QString action = pluginSettings->value(*keyit,QString()).toString();
                LOG_DEBUG(l) << "action: " << action.toStdString();

                MenuTextItem *mti = NULL;
                mti = fbmc->createMenuTextItem(ntm, *keyit, false, false);
                mti->setSelected(false);
                fbmc->addWidgetActionWithMapper(ntm, mti, &mapper, action, true, true);
                ntm->addSeparator();
                activeEntries++;
            }
            pluginSettings->endGroup();

            QPoint x = origPos;
            x.setY(origPos.y() + (2 - activeEntries) * elemHeight);
            x.setY(x.y() + (abs(2 - activeEntries) * 10));

            //cout << qPrintable(QString("x %1 | y %2").arg(x.x()).arg(x.y())) << endl << flush;

            ntm->move(x);
            ntm->update();
            ntm->layout();
        }
    }
}
Пример #2
0
bool TweaksPlugin::createHomeMenuEntry(QString mapping, QString icon, QString text, HomeMenuController *hmc, NickelTouchMenu *ntm)
{
    MenuTextItem *mti = NULL;

    mti = hmc->createMenuTextItem(ntm, text, false);
    if(!icon.isEmpty())
        mti->setSelectedImage(icon);

    mti->setSelected(true);
    hmc->addWidgetActionWithMapper(ntm, mti, &mapper, mapping, true, true);
    ntm->addSeparator();
    return true;
}