Esempio n. 1
0
void KCMessageBox::keyPressEvent(QKeyEvent *e)
{
    switch(e->key())
    {
    case Qt::Key_Enter:
    case Qt::Key_Return:
        messageFilter(KCMessageBoxPanel::buttonOK);
        animateClose();
        break;
    case Qt::Key_Escape:
        messageFilter(KCMessageBoxPanel::buttonCancel);
        animateClose();
        break;
    default:
        QDialog::keyPressEvent(e);
        break;
    }
}
void ContextMenuActionProvider::addIrcUserActions(QMenu *menu, const QModelIndex &index)
{
    // this can be called: a) as a nicklist context menu (index has IrcUserItemType)
    //                     b) as a query buffer context menu (index has BufferItemType and is a QueryBufferItem)
    //                     c) right-click in a query chatview (same as b), index will be the corresponding QueryBufferItem)
    //                     d) right-click on some nickname (_contextItem will be non-null, _filter -> chatview, index -> message buffer)

    if (contextItem().isNull()) {
        // cases a, b, c
        bool haveQuery = indexList().count() == 1 && findQueryBuffer(index).isValid();
        NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());
        addAction(_nickModeMenuAction, menu, itemType == NetworkModel::IrcUserItemType);
        addAction(_nickCtcpMenuAction, menu);

        IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
        if (ircUser) {
            Network *network = ircUser->network();
            // only show entries for usermode +h if server supports it
            if (network && network->prefixModes().contains('h')) {
                action(NickHalfop)->setVisible(true);
                action(NickDehalfop)->setVisible(true);
            }
            else {
                action(NickHalfop)->setVisible(false);
                action(NickDehalfop)->setVisible(false);
            }
            // ignoreliststuff
            QString bufferName;
            BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
            if (bufferInfo.type() == BufferInfo::ChannelBuffer)
                bufferName = bufferInfo.bufferName();
            QMap<QString, bool> ignoreMap = Client::ignoreListManager()->matchingRulesForHostmask(ircUser->hostmask(), ircUser->network()->networkName(), bufferName);
            addIgnoreMenu(menu, ircUser->hostmask(), ignoreMap);
            // end of ignoreliststuff
        }
        menu->addSeparator();
        addAction(NickQuery, menu, itemType == NetworkModel::IrcUserItemType && !haveQuery && indexList().count() == 1);
        addAction(NickSwitchTo, menu, itemType == NetworkModel::IrcUserItemType && haveQuery);
        menu->addSeparator();
        addAction(NickWhois, menu, true);
    }
    else if (!contextItem().isEmpty() && messageFilter()) {
        // case d
        // TODO
    }
}
Esempio n. 3
0
//Message Box Title
KCMessageBox::KCMessageBox(QWidget *parent) :
    QDialog(parent)
{
    //Set properties
    setWindowFlags(windowFlags() | Qt::ToolTip);
    setWindowOpacity(0.95);

    //Set default value
    messageState=KCMessageBoxPanel::none;

    //Set layout
    mainLayout=new QVBoxLayout(this);
    mainLayout->setContentsMargins(0,0,0,0);
    mainLayout->setSpacing(0);
    setLayout(mainLayout);

    //Set title
    title=new KCMessageBoxTitle(this);
    mainLayout->addWidget(title);

    context=new KCMessageBoxContext(this);
    mainLayout->addWidget(context, 1);

    //Set panel
    panel=new KCMessageBoxPanel(this);
    mainLayout->addWidget(panel);

    connect(panel, SIGNAL(requiredMessage(KCMessageBoxPanel::buttonState)),
            this, SLOT(messageFilter(KCMessageBoxPanel::buttonState)));
    connect(panel, SIGNAL(requiredExit()),
            this, SLOT(animateClose()));

    showAnimation=new QSequentialAnimationGroup(this);

    widthExpand=new QPropertyAnimation(this, "geometry", this);
    widthExpand->setDuration(100);

    heightExpand=new QPropertyAnimation(this, "geometry", this);
    heightExpand->setDuration(150);
    heightExpand->setEasingCurve(QEasingCurve::OutCubic);

    exitAnimation=new QPropertyAnimation(this, "geometry", this);
    exitAnimation->setDuration(100);
    connect(exitAnimation, SIGNAL(finished()),
            this, SLOT(close()));
}
void ContextMenuActionProvider::addIrcUserActions(QMenu *menu, const QModelIndex &index) {
  // this can be called: a) as a nicklist context menu (index has IrcUserItemType)
  //                     b) as a query buffer context menu (index has BufferItemType and is a QueryBufferItem)
  //                     c) right-click in a query chatview (same as b), index will be the corresponding QueryBufferItem)
  //                     d) right-click on some nickname (_contextItem will be non-null, _filter -> chatview, index -> message buffer)

  if(contextItem().isNull()) {
    // cases a, b, c
    bool haveQuery = indexList().count() == 1 && findQueryBuffer(index).isValid();
    NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());
    addAction(_nickModeMenuAction, menu, itemType == NetworkModel::IrcUserItemType);
    addAction(_nickCtcpMenuAction, menu);
    menu->addSeparator();
    addAction(NickQuery, menu, itemType == NetworkModel::IrcUserItemType && !haveQuery && indexList().count() == 1);
    addAction(NickSwitchTo, menu, itemType == NetworkModel::IrcUserItemType && haveQuery);
    menu->addSeparator();
    addAction(NickWhois, menu, true);

  } else if(!contextItem().isEmpty() && messageFilter()) {
    // case d
    // TODO

  }
}
// add a list of actions sensible for the current item(s)
void ContextMenuActionProvider::addActions(QMenu *menu,
    const QList<QModelIndex> &indexList_,
    MessageFilter *filter_,
    const QString &contextItem_,
    QObject *receiver_,
    const char *method_,
    bool isCustomBufferView)
{
    if (!indexList_.count())
        return;

    setIndexList(indexList_);
    setMessageFilter(filter_);
    setContextItem(contextItem_);
    setSlot(receiver_, method_);

    if (!messageFilter()) {
        // this means we are in a BufferView (or NickView) rather than a ChatView

        // first index in list determines the menu type (just in case we have both buffers and networks selected, for example)
        QModelIndex index = indexList().at(0);
        NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());

        switch (itemType) {
        case NetworkModel::NetworkItemType:
            addNetworkItemActions(menu, index);
            break;
        case NetworkModel::BufferItemType:
            addBufferItemActions(menu, index, isCustomBufferView);
            break;
        case NetworkModel::IrcUserItemType:
            addIrcUserActions(menu, index);
            break;
        default:
            return;
        }
    }
    else {
        // ChatView actions
        if (contextItem().isEmpty()) {
            // a) query buffer: handle like ircuser
            // b) general chatview: handle like channel iff it displays a single buffer
            // NOTE stuff breaks probably with merged buffers, need to rework a lot around here then
            if (messageFilter()->containedBuffers().count() == 1) {
                // we can handle this like a single bufferItem
                QModelIndex index = Client::networkModel()->bufferIndex(messageFilter()->containedBuffers().values().at(0));
                setIndexList(index);
                addBufferItemActions(menu, index);
                return;
            }
            else {
                // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on
            }
        }
        else {
            // context item = chan or nick, _indexList = buf where the msg clicked on originated
            if (isChannelName(contextItem())) {
                QModelIndex msgIdx = indexList().at(0);
                if (!msgIdx.isValid())
                    return;
                NetworkId networkId = msgIdx.data(NetworkModel::NetworkIdRole).value<NetworkId>();
                BufferId bufId = Client::networkModel()->bufferId(networkId, contextItem());
                if (bufId.isValid()) {
                    QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId);
                    setIndexList(targetIdx);
                    addAction(BufferJoin, menu, targetIdx, InactiveState);
                    addAction(BufferSwitchTo, menu, targetIdx, ActiveState);
                }
                else
                    addAction(JoinChannel, menu);
            }
            else {
                // TODO: actions for a nick
            }
        }
    }
}