예제 #1
0
파일: helpers.cpp 프로젝트: KDE/kpmcore
void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree)
{
    QMenu headerMenu(xi18nc("@title:menu", "Columns"));

    QHeaderView* header = tree.header();

    for (qint32 i = 0; i < tree.model()->columnCount(); i++) {
        const int idx = header->logicalIndex(i);
        const QString text = tree.model()->headerData(idx, Qt::Horizontal).toString();

        QAction* action = headerMenu.addAction(text);
        action->setCheckable(true);
        action->setChecked(!header->isSectionHidden(idx));
        action->setData(idx);
        action->setEnabled(idx > 0);
    }

    QAction* action = headerMenu.exec(tree.header()->mapToGlobal(p));

    if (action != nullptr) {
        const bool hidden = !action->isChecked();
        tree.setColumnHidden(action->data().toInt(), hidden);
        if (!hidden)
            tree.resizeColumnToContents(action->data().toInt());
    }
}
예제 #2
0
/****************************************************************************
**
** Copyright (C) 2015
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QHeaderView>
#include <QEvent>
#include <QImage>
#include <QPixmap>
#include <QTreeWidgetItem>
#include "tool_sceneviewwidget.h"

namespace Magus
{
//****************************************************************************/
QtSceneViewWidget::QtSceneViewWidget(const QString& iconDir, QWidget* parent) : QWidget(parent)
{
    setWindowTitle(QString("Scene view"));
    mIconDir = iconDir;
    QVBoxLayout* mainLayout = new QVBoxLayout;
    mSearchLayout = new QHBoxLayout;
    mTreeLayout = new QVBoxLayout;

    // Create edit
    mSearchLine = new QLineEdit();
    connect(mSearchLine, SIGNAL(textChanged(QString)), this, SLOT(searchLineTextChanged(QString)));

    // Create findbutton
    QImage imageSearch(mIconDir + TOOL_SCENEVIEW_ICON_SEARCH);
    QPixmap pixMapSearch = QPixmap::fromImage(imageSearch).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    mSearchLabel = new QLabel();
    mSearchLabel->setPixmap(pixMapSearch);
    mSearchLabel->setContentsMargins(-8, -8, -8, -8);

    // Create clearbutton
    QImage imageClear(mIconDir + TOOL_SCENEVIEW_ICON_CLOSE);
    QPixmap pixMapClear = QPixmap::fromImage(imageClear).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    mSearchClearButton = new QPushButton();
    mSearchClearButton->setStyleSheet(QString("QPushButton {border: none; background: transparent;} QPushButton:hover {background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #565656, stop:1 #464646);}"));
    mSearchClearButton->setIcon(QIcon(pixMapClear));
    mSearchClearButton->setIconSize(QSize(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH));
    mSearchClearButton->setContentsMargins(-8, -8, -8, -8);
    connect(mSearchClearButton, SIGNAL(clicked()), this, SLOT(clearSearchLine()));


    // Misc
    mVisibilityIconVisibleForGroups = true;
    mVisibilityIconVisibleForAssets = true;
    mDeletionIconVisibleForGroups = true;
    mDeletionIconVisibleForAssets = true;

    // Layout
    mSearchLayout->addWidget(mSearchLabel, 1);
    mSearchLayout->addWidget(mSearchLine, 2000);
    mSearchLayout->addWidget(mSearchClearButton, 1);
    setVisibilitySearchWidgets(false);
    mainLayout->addLayout(mSearchLayout, 1);
    mainLayout->addLayout(mTreeLayout, 2000);
    setLayout(mainLayout);
}

//****************************************************************************/
QtSceneViewWidget::~QtSceneViewWidget(void)
{
    // Delete all QtAssetGroups in mAssetGroupMap
    foreach (QtAssetGroup* group, mAssetGroupMap)
        delete group;

    mAssetGroupMap.clear();

}

//****************************************************************************/
bool QtSceneViewWidget::eventFilter(QObject* object, QEvent* event)
{
    QMouseEvent* mouseEvent = (QMouseEvent*) event;
    switch ((int) event->type())
    {
    case QEvent::MouseButtonPress:
        mouseClickHandler(mouseEvent);
        break;
    }
    return QObject::eventFilter(object, event);
}

//****************************************************************************/
void QtSceneViewWidget::mouseClickHandler(QMouseEvent* event)
{
    switch ((int) event->button())
    {
    case Qt::LeftButton:
    {
        // Get the selected item of the visible sceneview
        QTreeWidget* sceneView = getCurrentVisibleScene();
        if (sceneView)
        {
            QTreeWidgetItem* item = sceneView->itemAt(event->pos());
            int col = sceneView->columnAt(event->pos().x());
            if (itemIsGroup(item))
            {
                if (col == TOOL_SCENEVIEW_COLUMN_GROUP_CLOSE)
                {
                    handleDeletionOfGroup(sceneView, item);
                    return;
                }
                else if (col == TOOL_SCENEVIEW_COLUMN_GROUP_VISIBILITY)
                {
                    // Toggle visibility
                    toggleVisibilityOfGroup(item);
                }

                int groupId = getGroupIdOfGroupItem(item);
                emit groupSelected(sceneView, groupId);
            }
            else if (itemIsAsset(item))
            {
                if (col == TOOL_SCENEVIEW_COLUMN_ASSET_CLOSE)
                {
                    handleDeletionOfAsset(sceneView, item);
                    return;
                }
                else if (col == TOOL_SCENEVIEW_COLUMN_ASSET_VISIBILITY)
                {
                    // Toggle visibility
                    toggleVisibilityOfAsset(item);
                }

                int groupId = getGroupIdOfAssetItem(item);
                int assetId = getAssetIdOfAssetItem(item);
                emit assetSelected(sceneView, groupId, assetId);
            }
        }
    }
    break;

    case Qt::RightButton:
    {
        // TODO
    }
    break;
    }
}

//****************************************************************************/
bool QtSceneViewWidget::groupIsVisible(QTreeWidgetItem* groupItem)
{
    if (itemIsGroup(groupItem))
    {
        return (groupItem->data(TOOL_SCENEVIEW_KEY_VISIBLE, Qt::UserRole)).toBool();
    }

    return false;
}

//****************************************************************************/
bool QtSceneViewWidget::groupOfAssetItemIsVisible(QTreeWidgetItem* assetItem)
{
    if (itemIsAsset(assetItem))
    {
        QTreeWidgetItem* groupItem = assetItem->parent();
        if (groupItem)
        {
            return (groupItem->data(TOOL_SCENEVIEW_KEY_VISIBLE, Qt::UserRole)).toBool();
        }
    }

    return false;
}

//****************************************************************************/
bool QtSceneViewWidget::assetIsVisible(QTreeWidgetItem* assetItem)
{
    if (itemIsAsset(assetItem))
    {
        return (assetItem->data(TOOL_SCENEVIEW_KEY_VISIBLE, Qt::UserRole)).toBool();
    }

    return false;
}

//****************************************************************************/
void QtSceneViewWidget::toggleVisibilityOfGroup(QTreeWidgetItem* groupItem)
{
    if (!groupItem)
        return;

    bool visible = groupIsVisible(groupItem);
    setVisibilityOfGroup(groupItem, !visible);
}

//****************************************************************************/
void QtSceneViewWidget::setVisibilityOfGroup(int sceneId, int groupId, bool visible)
{
    QTreeWidgetItem* groupItem = getGroupItem(sceneId, groupId);
    setVisibilityOfGroup(groupItem, visible);
}

//****************************************************************************/
void QtSceneViewWidget::setVisibilityOfAllGroups(int sceneId, bool visible)
{
    QTreeWidget* sceneView = getSceneView(sceneId);
    QTreeWidgetItemIterator it(sceneView);
    while (*it)
    {
        if (itemIsGroup(*it))
            setVisibilityOfGroup(*it, visible);

        ++it;
    }
}

//****************************************************************************/
void QtSceneViewWidget::setVisibilityOfGroup(QTreeWidgetItem* groupItem, bool visible)
{
    if (!mVisibilityIconVisibleForGroups)
        return;

    if (!groupItem)
        return;

    // Set the icon
    QImage imageVis;
    if (visible)
        imageVis = QImage(mIconDir + TOOL_SCENEVIEW_ICON_VISIBLE);
    else
        imageVis = QImage(mIconDir + TOOL_SCENEVIEW_ICON_INVISIBLE);

    QPixmap pixMapVis = QPixmap::fromImage(imageVis).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    groupItem->setData(TOOL_SCENEVIEW_COLUMN_GROUP_VISIBILITY, Qt::DecorationRole, QVariant(pixMapVis));

    // Set the visibility flag
    groupItem->setData(TOOL_SCENEVIEW_KEY_VISIBLE, Qt::UserRole, QVariant(visible));

    // Signal that visibility of a group is changed
    emit groupVisibiltyChanged(getCurrentVisibleScene(), getGroupIdOfGroupItem(groupItem));

    // Set visibility of the children
    QTreeWidgetItemIterator it(groupItem);
    while (*it)
    {
        if (itemIsAsset(*it) && (*it)->parent() == groupItem)
            setVisibilityOfAsset(*it, visible);

        ++it;
    }
}

//****************************************************************************/
void QtSceneViewWidget::toggleVisibilityOfAsset(QTreeWidgetItem* assetItem)
{
    if (!assetItem)
        return;

    // Make asset only visisble/invisible if the parent group is visible;
    // if the group is not visible, the assets cannot be toggled.
    if (!groupOfAssetItemIsVisible(assetItem))
        return;

    bool visible = assetIsVisible(assetItem);
    setVisibilityOfAsset(assetItem, !visible);
}

//****************************************************************************/
void QtSceneViewWidget::setVisibilityOfAsset(int sceneId, int assetId, bool visible)
{
    QTreeWidgetItem* assetItem = getAssetItem(sceneId, assetId);
    setVisibilityOfAsset(assetItem, visible);
}

//****************************************************************************/
void QtSceneViewWidget::setVisibilityOfAsset(QTreeWidgetItem* assetItem, bool visible)
{
    if (!mVisibilityIconVisibleForAssets)
        return;

    if (!assetItem)
        return;

    // Set the icon
    QImage imageVis;
    if (visible)
        imageVis = QImage(mIconDir + TOOL_SCENEVIEW_ICON_VISIBLE);
    else
        imageVis = QImage(mIconDir + TOOL_SCENEVIEW_ICON_INVISIBLE);

    QPixmap pixMapVis = QPixmap::fromImage(imageVis).scaled(TOOL_SCENEVIEW_ICON_WIDTH, TOOL_SCENEVIEW_ICON_WIDTH);
    assetItem->setData(TOOL_SCENEVIEW_COLUMN_ASSET_VISIBILITY, Qt::DecorationRole, QVariant(pixMapVis));

    // Set the visibility flag
    assetItem->setData(TOOL_SCENEVIEW_KEY_VISIBLE, Qt::UserRole, QVariant(visible));

    // Signal that visibility of a group is changed
    emit groupVisibiltyChanged(getCurrentVisibleScene(), getGroupIdOfGroupItem(assetItem));
}

//****************************************************************************/
void QtSceneViewWidget::handleDeletionOfGroup(QTreeWidget* sceneView, QTreeWidgetItem* groupItem)
{
    if (!mDeletionIconVisibleForGroups)
        return;

    if (!groupItem)
        return;

    int groupId = getGroupIdOfGroupItem(groupItem);
    handleDeletionOfItem(sceneView, groupItem);

    // Emit signal
    emit groupDeleted(sceneView, groupId);
    emit groupDeleted(getSceneId(sceneView), groupId);
}

//****************************************************************************/
void QtSceneViewWidget::handleDeletionOfAsset(QTreeWidget* sceneView, QTreeWidgetItem* assetItem)
{
    if (!mDeletionIconVisibleForAssets)
        return;

    if (!assetItem)
        return;

    int groupId = getGroupIdOfAssetItem(assetItem);
    int assetId = getAssetIdOfAssetItem(assetItem);
    handleDeletionOfItem(sceneView, assetItem);

    // Emit signal
    emit assetDeleted(sceneView, groupId, assetId);
    emit assetDeleted(getSceneId(sceneView), groupId, assetId);
}

//****************************************************************************/
void QtSceneViewWidget::handleDeletionOfItem(QTreeWidget* sceneView, QTreeWidgetItem* item)
{
    if (!item)
        return;

    int index = sceneView->indexOfTopLevelItem(item);
    sceneView->takeTopLevelItem(index);
    delete item;
}

//****************************************************************************/
QTreeWidget* QtSceneViewWidget::createSceneView (int sceneId)
{
    // Create tree
    QTreeWidget* sceneView = new QTreeWidget(this);
    sceneView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    sceneView->setAnimated(true);
    sceneView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    sceneView->setDragEnabled(true);
    sceneView->viewport()->installEventFilter(this);

    // Set headers
    QStringList headers;
    headers << tr("") << tr("Asset Group") << tr("Visibility") << tr("Remove");
    sceneView->setHeaderLabels(headers);
    QFont font;
    font.setBold(true);
    sceneView->header()->setFont(font);

    // Add it to the map
    mSceneViewMap[sceneId] = sceneView;

    // Add the groups
    foreach (QtAssetGroup* group , mAssetGroupMap)
        addGroupToSceneView (sceneView, group->groupIcon, group->groupId, group->groupName);

    // Layout
    mTreeLayout->addWidget(sceneView);
    setVisibilitySearchWidgets(true);
    return sceneView;
}
예제 #3
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QStringList args = QApplication::arguments();

    if (args.count() < 2) {
        std::cerr << "Usage: saxhandler file1.xml..." << std::endl;
        return 1;
    }

    QStringList labels;
    labels << QObject::tr("Terms") << QObject::tr("Pages");

    QTreeWidget treeWidget;
    treeWidget.setHeaderLabels(labels);
    treeWidget.header()->setResizeMode(QHeaderView::Stretch);
    treeWidget.setWindowTitle(QObject::tr("SAX Handler"));
    treeWidget.show();

    SaxHandler handler(&treeWidget);
    for (int i = 1; i < args.count(); ++i)
        handler.readFile(args[i]);

    return app.exec();
}
예제 #4
0
QWidget *PluginAboutPage::createPage(QWidget *parent)
{
    if (!m_Spec)
        return new QWidget(parent);

    QWidget *w = new QWidget(parent);
    QVBoxLayout *layout = new QVBoxLayout(w);
    layout->setSpacing(0);
    layout->setMargin(0);
    QTreeWidget *tree = new QTreeWidget(w);
    tree->header()->hide();
    layout->addWidget(tree);
    QLabel *lbl = new QLabel(w);
    lbl->setText(tkTr(Trans::Constants::DESCRIPTION));
    layout->addWidget(lbl);
    QTextBrowser *tb = new QTextBrowser(w);
    layout->addWidget(tb);

    // popuplate tree
    tree->clear();
    QFont f;
    f.setBold(true);
    QTreeWidgetItem *i = 0;
    i = new QTreeWidgetItem(tree, QStringList() << tkTr(Trans::Constants::INFORMATION));
    i->setFont(0,f);
    new QTreeWidgetItem(i, QStringList() << tkTr(Trans::Constants::VERSION) + " " + m_Spec->version() );
    if (Utils::isDebugWithoutInstallCompilation()) {
        new QTreeWidgetItem( i, QStringList() << tkTr(Trans::Constants::BUILD_DEBUG) + " - no install");
    } else {
        new QTreeWidgetItem( i, QStringList() << tkTr(Trans::Constants::BUILD_RELEASE) );
    }
    new QTreeWidgetItem(i, QStringList() << "License: " + m_Spec->license());
    tree->expandAll();

    // populate textbrowser
    tb->setPlainText(m_Spec->description());

    return w;
}
예제 #5
0
SimpleQTreeWidgetWidthInterface::SimpleQTreeWidgetWidthInterface(QTreeWidget& tbl) : TableWidthInterface(tbl.columnCount()), m_tbl(tbl)
{
    int nCols (m_tbl.columnCount());
    m_vbBold.resize(nCols);

    QFont font (m_tbl.font());
    font.setBold(true);
    QFontMetrics fontMetrics (font);

    QHeaderView* pHdr (tbl.header());

    for (int j = 0; j < nCols; ++j)
    {
        if (pHdr->isSectionHidden(j))
        {
            setFixedWidth(j, 0);
        }
        else
        {
            m_vnHdrWidth[j] = fontMetrics.width(m_tbl.headerItem()->text(j)) + 8/*2*QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth)*/; // PM_DefaultFrameWidth is not THE thing to use, but it's one way to get some spacing for the header; (well it turned up to be too small, so it got replaced by 8; probably look at the source to see what should be used)
        }
    }
}
예제 #6
0
void VVimIndicator::setupUI()
{
    m_cmdLineEdit = new VVimCmdLineEdit(this);
    m_cmdLineEdit->setProperty("VimCommandLine", true);
    connect(m_cmdLineEdit, &VVimCmdLineEdit::commandCancelled,
            this, [this](){
                if (m_editTab) {
                    m_editTab->focusTab();
                }

                // NOTICE: m_cmdLineEdit should not hide itself before setting
                // focus to edit tab.
                m_cmdLineEdit->hide();

                if (m_vim) {
                    m_vim->processCommandLineCancelled();
                }
            });

    connect(m_cmdLineEdit, &VVimCmdLineEdit::commandFinished,
            this, [this](VVim::CommandLineType p_type, const QString &p_cmd){
                if (m_editTab) {
                    m_editTab->focusTab();
                }

                m_cmdLineEdit->hide();

                // Hide the cmd line edit before execute the command.
                // If we execute the command first, we will get Chinese input
                // method enabled after returning to read mode.
                if (m_vim) {
                    m_vim->processCommandLine(p_type, p_cmd);
                }
            });

    connect(m_cmdLineEdit, &VVimCmdLineEdit::commandChanged,
            this, [this](VVim::CommandLineType p_type, const QString &p_cmd){
                if (m_vim) {
                    m_vim->processCommandLineChanged(p_type, p_cmd);
                }
            });

    connect(m_cmdLineEdit, &VVimCmdLineEdit::requestNextCommand,
            this, [this](VVim::CommandLineType p_type, const QString &p_cmd){
                if (m_vim) {
                    QString cmd = m_vim->getNextCommandHistory(p_type, p_cmd);
                    if (!cmd.isNull()) {
                        m_cmdLineEdit->setCommand(cmd);
                    } else {
                        m_cmdLineEdit->restoreUserLastInput();
                    }
                }
            });

    connect(m_cmdLineEdit, &VVimCmdLineEdit::requestPreviousCommand,
            this, [this](VVim::CommandLineType p_type, const QString &p_cmd){
                if (m_vim) {
                    QString cmd = m_vim->getPreviousCommandHistory(p_type, p_cmd);
                    if (!cmd.isNull()) {
                        m_cmdLineEdit->setCommand(cmd);
                    }
                }
            });

    connect(m_cmdLineEdit, &VVimCmdLineEdit::requestRegister,
            this, [this](int p_key, int p_modifiers){
                if (m_vim) {
                    QString val = m_vim->readRegister(p_key, p_modifiers);
                    if (!val.isEmpty()) {
                        m_cmdLineEdit->setText(m_cmdLineEdit->text() + val);
                    }
                }
            });

    m_cmdLineEdit->hide();

    m_modeLabel = new QLabel(this);
    m_modeLabel->setProperty("VimIndicatorModeLabel", true);

    QTreeWidget *regTree = new QTreeWidget(this);
    regTree->setProperty("ItemBorder", true);
    regTree->setRootIsDecorated(false);
    regTree->setColumnCount(2);
    regTree->header()->setStretchLastSection(true);
    QStringList headers;
    headers << tr("Register") << tr("Value");
    regTree->setHeaderLabels(headers);

    m_regBtn = new VButtonWithWidget("\"",
                                     regTree,
                                     this);
    m_regBtn->setToolTip(tr("Registers"));
    m_regBtn->setProperty("StatusBtn", true);
    m_regBtn->setFocusPolicy(Qt::NoFocus);
    connect(m_regBtn, &VButtonWithWidget::popupWidgetAboutToShow,
            this, &VVimIndicator::updateRegistersTree);

    QTreeWidget *markTree = new QTreeWidget(this);
    markTree->setProperty("ItemBorder", true);
    markTree->setRootIsDecorated(false);
    markTree->setColumnCount(4);
    markTree->header()->setStretchLastSection(true);
    headers.clear();
    headers << tr("Mark") << tr("Line") << tr("Column") << tr("Text");
    markTree->setHeaderLabels(headers);

    m_markBtn = new VButtonWithWidget("[]",
                                      markTree,
                                      this);
    m_markBtn->setToolTip(tr("Marks"));
    m_markBtn->setProperty("StatusBtn", true);
    m_markBtn->setFocusPolicy(Qt::NoFocus);
    connect(m_markBtn, &VButtonWithWidget::popupWidgetAboutToShow,
            this, &VVimIndicator::updateMarksTree);

    m_keyLabel = new QLabel(this);
    m_keyLabel->setProperty("VimIndicatorKeyLabel", true);
    QFontMetrics metric(font());
    m_keyLabel->setMinimumWidth(metric.width('A') * 5);

    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->addStretch();
    mainLayout->addWidget(m_cmdLineEdit);
    mainLayout->addWidget(m_modeLabel);
    mainLayout->addWidget(m_regBtn);
    mainLayout->addWidget(m_markBtn);
    mainLayout->addWidget(m_keyLabel);
    mainLayout->setContentsMargins(0, 0, 0, 0);

    setLayout(mainLayout);
}
예제 #7
0
/* json
HostInfoWidget::HostInfoWidget(QList<QStringList> listOfStringLists, QString TimeFormat,int TimeZone, QString ServiceURL,int uniqObjectID, QWidget * parent, Qt::WindowFlags f): QWidget( parent, f )
{
    uid=uniqObjectID;
    SURL=ServiceURL;

    Hostname=listOfStringLists.at(0).at(0);
    NotesUrl=listOfStringLists.at(0).at(11);
    ActionUrl=listOfStringLists.at(0).at(12);


     resize(800,640);
     setWindowTitle("HostInfo for " + Hostname);
     QGridLayout* mainGrid = new QGridLayout(this);

     //Lets get the info, request was:
     //GET hosts\nColumns:host_name alias display_name address state last_time_down comments_with_info services_with_info contacts downtimes_with_info last_hard_state_change notes_url_expanded action_url_expanded plugin_output contact_groups parents childs  host_groups worst_service_state perf_data\n
     //                     0       1       2           3       4           5           6                   7                   8       9                   10                      11                  12              13              14              15  16      17          18                  19
     //Filter: host_name = " + host +" \nLimit: 1\n";

    int k = 0;
    int r=0;
    mainGrid->addWidget(new QLabel("Hostname:",this),r,0);
    QLabel* L_Hostname = new QLabel(Hostname,this);
            L_Hostname->setTextInteractionFlags(Qt::TextSelectableByMouse);
    mainGrid->addWidget(L_Hostname,r,1,1,2);

    r=1;
    qDebug() <<r;
    mainGrid->addWidget(new QLabel("Address:",this),r,0);
    QLabel* L_Address = new QLabel(listOfStringLists.at(k).at(3),this);
            L_Address->setTextInteractionFlags(Qt::TextSelectableByMouse);
    mainGrid->addWidget(L_Address,r,1,1,2);

    r=2;
    qDebug() <<r;
    mainGrid->addWidget(new QLabel("State:",this),r,0);
    QLabel* stateLabel = new QLabel(this);
    if (listOfStringLists.at(k).at(4) == "0")
    {
        stateLabel->setPixmap(QPixmap(ok_xpm));
    }
    else if (listOfStringLists.at(k).at(4) == "1")
    {
        stateLabel->setPixmap(QPixmap(warning_xpm));

    }
    else if (listOfStringLists.at(k).at(4).toInt() >= 2)
    {
        stateLabel->setPixmap(QPixmap(critical_xpm));
    }
    mainGrid->addWidget(stateLabel,r,1);

    // Plugin OUtput

    QLabel* L_Output = new QLabel(listOfStringLists.at(k).at(13),this);
            L_Output->setTextInteractionFlags(Qt::TextSelectableByMouse);
    mainGrid->addWidget(L_Output,r,2);
    mainGrid->addItem(new QSpacerItem ( 10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed ),r,3);


    //last_hard_state_change

//Item->setText(3,dt.toString("HH:mm dd-MM-yy"));
    r=3;
    //inputTimezone->value()
    QDateTime lcdt = QDateTime::fromString("01-01-70 00:00:00", "dd-MM-yy HH:mm:ss").addSecs(QString(listOfStringLists.at(k).at(10)).toInt()+(3600*TimeZone));
    mainGrid->addWidget(new QLabel("Last Change:",this),r,0);
    QLabel* L_LastChange = new QLabel(lcdt.toString(TimeFormat),this);
            L_LastChange->setTextInteractionFlags(Qt::TextSelectableByMouse);
    mainGrid->addWidget(L_LastChange,r,1,1,2);



    //contacts (8) & contact_groups (14)
    r=4;
    mainGrid->addWidget(new QLabel("Contacts:",this),r,0);
    QComboBox* contactBox = new QComboBox(this);
        contactBox->addItems(listOfStringLists.at(k).at(8).split(","));
    mainGrid->addWidget(contactBox,r,1,1,2);

    r=5;
    mainGrid->addWidget(new QLabel("Groups:",this),r,0);
    QComboBox* contactGroupBox = new QComboBox(this);
        contactGroupBox->addItems(listOfStringLists.at(k).at(14).split(","));
        mainGrid->addWidget(contactGroupBox,r,1,1,2);


    // Hostgroups (17)
    r=6;
    mainGrid->addWidget(new QLabel("Hostgroups:",this),r,0);
    QComboBox* hostGroupBox = new QComboBox(this);
        hostGroupBox->addItems(listOfStringLists.at(k).at(17).split(","));
        mainGrid->addWidget(hostGroupBox,r,1,1,2);

    r=7;
    mainGrid->addWidget(new QLabel(" ",this),r,0);

    r=8;
    mainGrid->addWidget(new QLabel("Services:",this),r,0);
    r=9;
    //services_with_state (7)
    QTreeWidget* serviceTree = new QTreeWidget(this);
        serviceTree->setSelectionMode(QAbstractItemView::SingleSelection);
        serviceTree->setColumnCount(2);
        serviceTree->setMaximumWidth(600);
        serviceTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
        QStringList headerLabelsService;
        headerLabelsService << "Service" << "Output";
        serviceTree->setHeaderLabels(headerLabelsService);
        serviceTree->setSortingEnabled (false);
     mainGrid->addWidget(serviceTree,r,0,1,5);



     //QStringList listServices = QString(listOfStringLists.at(k).at(7)).contains();


    QStringList ServiceList;
    QStringList StateList;
    QStringList OutputList;

     // lets get the services (ugly format)
     QString state_with_info="," + QString(listOfStringLists.at(k).at(7));
     QRegularExpression re("(,(\\w|\\d|/|:| )+\\|)");
     QRegularExpressionMatchIterator i = re.globalMatch(state_with_info);
     while (i.hasNext())
     {
         QRegularExpressionMatch match = i.next();

         // Lets create a String List with Service name
         ServiceList << match.captured(0).remove(",").remove("|");

         //Here comes the trick, just remove what we just found, we need it nomore, but don't removw the seperating pipe
         state_with_info.remove(match.captured(0).remove("|"));
         qDebug()<< "use match" << match.captured(0);
     }
     qDebug() << "state_with_info" << state_with_info;

     //Lets find the State
     QRegularExpression re2("\\|\\d+\\|\\d+\\|");
     QRegularExpressionMatchIterator i2 = re2.globalMatch(state_with_info);
     while (i2.hasNext())
     {
            QRegularExpressionMatch match = i2.next();
            qDebug()<< "use match 2" << match.captured(0);
            qDebug() << "state" << match.captured(0).split("|")[1];

            StateList << match.captured(0).split("|")[1];
            state_with_info.replace(match.captured(0),"|");
     }
     qDebug() << "state_with_info" << state_with_info;

     // and last the output (remove first pipe
     state_with_info.remove(0,1);
     OutputList=state_with_info.split("|");

     for (int i=0;i<ServiceList.size();i++)
     {
         qDebug() << "ServicesList" << i << ServiceList.at(i) << StateList.at(i) << OutputList.at(i);
         QStringList tmp;
         tmp << ServiceList.at(i) <<  OutputList.at(i);
            QTreeWidgetItem* Item = new QTreeWidgetItem(tmp,QTreeWidgetItem::Type);
            if (StateList.at(i) == "0")
            {
                Item->setIcon(0, QIcon(QPixmap(ok_xpm)) );
            }
            else if (StateList.at(i) == "1")
            {
                Item->setIcon(0, QIcon(QPixmap(warning_xpm)) );
            }
            else
            {
                Item->setIcon(0, QIcon(QPixmap(critical_xpm)) );
            }
            serviceTree->insertTopLevelItem(0,Item);

     }

     r=1;
     QPushButton* browserUrlButton = new QPushButton("Open in Browser", this);
        connect( browserUrlButton, SIGNAL( pressed()) , this, SLOT( browserUrlButtonPressed() ) );
     mainGrid->addWidget(browserUrlButton,r,4);

     r=2;
     QPushButton* actionUrlButton = new QPushButton("Open Action URL", this);
        connect( actionUrlButton, SIGNAL( pressed()) , this, SLOT( actionUrlButtonPressed() ) );
     mainGrid->addWidget(actionUrlButton,r,4);

     r=3;
     QPushButton* notesUrlButton = new QPushButton("Open Notes URL", this);
        connect( notesUrlButton, SIGNAL( pressed()) , this, SLOT( notesUrlButtonPressed() ) );
     mainGrid->addWidget(notesUrlButton,r,4);

     r=4;
     QPushButton* logButton = new QPushButton("Open Log", this);
        connect( logButton, SIGNAL( pressed()) , this, SLOT( logButtonPressed() ) );
     mainGrid->addWidget(logButton,r,4);


     //Get overallstate
     //worst_service_state (18) + state (4)
     int overallState=listOfStringLists.at(k).at(18).toInt()+listOfStringLists.at(k).at(4).toInt();
     qDebug() << "overallState" << overallState;
     r=1;
     pcDialog = new PCDialog(Hostname, overallState, this);
     connect( pcDialog, SIGNAL(doubleClickedHost(QString)) , this, SLOT( slotDoubleClickedHost(QString) ) );
       mainGrid->addWidget(pcDialog,r,5,9,3);

     //Parents (15)
      parentList=listOfStringLists.at(k).at(15).split(",");
      parentList.sort();
      //pcDialog->setGeneration();
      for (int i=0;i<parentList.size();i++)
      {
          if (!parentList.at(i).trimmed().isEmpty())
          {
            pcDialog->addParent(parentList.at(i));
            //pcDialog->addNode(parentList.at(i),Hostname,127,"parent");
          }
      }

      //Childs (16)
       QStringList childList=listOfStringLists.at(k).at(16).split(",");
       childList.sort();
       for (int i=0;i<childList.size();i++)
       {

           if (!childList.at(i).trimmed().isEmpty())
           {
                pcDialog->addChild(childList.at(i));
                //pcDialog->addNode(childList.at(i),Hostname,127,"child");
           }
       }

       r=0;
       QPushButton* getParentsButton = new QPushButton("Get Parents", this);
          connect( getParentsButton, SIGNAL( pressed()) , this, SLOT( requestParents() ) );
       mainGrid->addWidget(getParentsButton,r,5);

       QPushButton* forceButton = new QPushButton("Force", this);
          connect( forceButton, SIGNAL( pressed()) , pcDialog, SLOT( force() ) );
       mainGrid->addWidget(forceButton,r,6);

       mainGrid->addItem(new QSpacerItem ( 10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed ),r,7);
      //last spacer
        //mainGrid->addItem(new QSpacerItem ( 300, 0, QSizePolicy::Maximum, QSizePolicy::Fixed ),10,1,1,5);
        mainGrid->addItem(new QSpacerItem ( 500, 0, QSizePolicy::Expanding, QSizePolicy::Fixed ),10,5);


}
*/
HostInfoWidget::HostInfoWidget(QJsonArray jsonArray, QString TimeFormat,int TimeZone, QString ServiceURL,int uniqObjectID, QWidget * parent, Qt::WindowFlags f): QWidget( parent, f )
{
    uid=uniqObjectID;
    SURL=ServiceURL;

    Hostname=jsonArray.at(0).toString();
    NotesUrl=jsonArray.at(11).toString();
    ActionUrl=jsonArray.at(12).toString();

    qDebug()<<"hsotname" << Hostname<<NotesUrl<<ActionUrl;

    resize(800,640);
    setWindowTitle("HostInfo for " + Hostname);
    QGridLayout* mainGrid = new QGridLayout(this);

    //Lets get the info, request was:
    //GET hosts\nColumns:host_name alias display_name address state last_time_down comments_with_info services_with_info contacts downtimes_with_info last_hard_state_change notes_url_expanded action_url_expanded plugin_output contact_groups parents childs  host_groups worst_service_state perf_data\n
    //                     0       1       2           3       4           5           6                   7                   8       9                   10                      11                  12              13              14              15  16      17          18                  19
    //Filter: host_name = " + host +" \nLimit: 1\n";

   int k = 0;
   int r=0;
   mainGrid->addWidget(new QLabel("Hostname:",this),r,0);
   QLabel* L_Hostname = new QLabel(Hostname,this);
           L_Hostname->setTextInteractionFlags(Qt::TextSelectableByMouse);
   mainGrid->addWidget(L_Hostname,r,1,1,2);

   r=1;
   qDebug() <<r;
   mainGrid->addWidget(new QLabel("Address:",this),r,0);
   QLabel* L_Address = new QLabel(jsonArray.at(3).toString(),this);
           L_Address->setTextInteractionFlags(Qt::TextSelectableByMouse);
   mainGrid->addWidget(L_Address,r,1,1,2);

   r=2;
   qDebug() <<r;
   mainGrid->addWidget(new QLabel("State:",this),r,0);
   QLabel* stateLabel = new QLabel(this);
   if (jsonArray.at(4).toDouble() == 0)
   {
       stateLabel->setPixmap(QPixmap(ok_xpm));
   }
   else if (jsonArray.at(4).toDouble() == 1)
   {
       stateLabel->setPixmap(QPixmap(warning_xpm));

   }
   else if (jsonArray.at(4).toDouble() >= 2)
   {
       stateLabel->setPixmap(QPixmap(critical_xpm));
   }
   mainGrid->addWidget(stateLabel,r,1);

   // Plugin OUtput

   QLabel* L_Output = new QLabel(jsonArray.at(13).toString(),this);
           L_Output->setTextInteractionFlags(Qt::TextSelectableByMouse);
   mainGrid->addWidget(L_Output,r,2);
   mainGrid->addItem(new QSpacerItem ( 10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed ),r,3);


   //last_hard_state_change

//Item->setText(3,dt.toString("HH:mm dd-MM-yy"));
   r=3;
   //inputTimezone->value()
   QDateTime lcdt = QDateTime::fromString("01-01-70 00:00:00", "dd-MM-yy HH:mm:ss").addSecs(jsonArray.at(10).toDouble()+(3600*TimeZone));
   mainGrid->addWidget(new QLabel("Last Change:",this),r,0);
   QLabel* L_LastChange = new QLabel(lcdt.toString(TimeFormat),this);
           L_LastChange->setTextInteractionFlags(Qt::TextSelectableByMouse);
   mainGrid->addWidget(L_LastChange,r,1,1,2);



   //contacts (8) & contact_groups (14)
   r=4;
   mainGrid->addWidget(new QLabel("Contacts:",this),r,0);
   QComboBox* contactBox = new QComboBox(this);
       QJsonArray jsonContactArray=jsonArray.at(8).toArray();
       for (int i=0;i<jsonContactArray.size();i++)
       {
           contactBox->addItem(jsonContactArray.at(i).toString());
       }
   mainGrid->addWidget(contactBox,r,1,1,2);

   r=5;
   mainGrid->addWidget(new QLabel("Groups:",this),r,0);
   QComboBox* contactGroupBox = new QComboBox(this);
       QJsonArray jsonGroupArray=jsonArray.at(14).toArray();
       for (int i=0;i<jsonGroupArray.size();i++)
       {
           contactGroupBox->addItem(jsonGroupArray.at(i).toString());
       }
    mainGrid->addWidget(contactGroupBox,r,1,1,2);


   // Hostgroups (17)
   r=6;
   mainGrid->addWidget(new QLabel("Hostgroups:",this),r,0);
   QComboBox* hostGroupBox = new QComboBox(this);
       QJsonArray jsonHostGroupArray=jsonArray.at(17).toArray();
       for (int i=0;i<jsonHostGroupArray.size();i++)
       {
           hostGroupBox->addItem(jsonHostGroupArray.at(i).toString());
       }
    mainGrid->addWidget(hostGroupBox,r,1,1,2);

   r=7;
   mainGrid->addWidget(new QLabel(" ",this),r,0);

   r=8;
   mainGrid->addWidget(new QLabel("Services:",this),r,0);

   r=9;
   //services_with_state (7)
   QTreeWidget* serviceTree = new QTreeWidget(this);
       serviceTree->setSelectionMode(QAbstractItemView::SingleSelection);
       serviceTree->setColumnCount(2);
       serviceTree->setMaximumWidth(600);
       serviceTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
       QStringList headerLabelsService;
       headerLabelsService << "Service" << "Output";
       serviceTree->setHeaderLabels(headerLabelsService);
       serviceTree->setSortingEnabled (false);
    mainGrid->addWidget(serviceTree,r,0,1,5);


    QJsonArray serviceJsonArray = jsonArray.at(7).toArray();
    qDebug() << "json service size" << serviceJsonArray.size();
    qDebug() << "json service " << serviceJsonArray.first();

    for (int i=0;i<serviceJsonArray.size();i++)
    {
        QJsonArray singleServiceJsonArray = serviceJsonArray.at(i).toArray();
        QStringList tmp;
        tmp << singleServiceJsonArray.at(0).toString() <<  singleServiceJsonArray.at(3).toString();
        qDebug() << "json service list" << singleServiceJsonArray.at(i).toString();
           QTreeWidgetItem* Item = new QTreeWidgetItem(tmp,QTreeWidgetItem::Type);

           if (singleServiceJsonArray.at(1).toDouble() == 0)
           {
               Item->setIcon(0, QIcon(QPixmap(ok_xpm)) );
           }
           else if (singleServiceJsonArray.at(1).toDouble() == 1)
           {
               Item->setIcon(0, QIcon(QPixmap(warning_xpm)) );
           }
           else
           {
               Item->setIcon(0, QIcon(QPixmap(critical_xpm)) );
           }
           serviceTree->insertTopLevelItem(0,Item);

    }

    r=1;
    QPushButton* browserUrlButton = new QPushButton("Open in Browser", this);
       connect( browserUrlButton, SIGNAL( pressed()) , this, SLOT( browserUrlButtonPressed() ) );
    mainGrid->addWidget(browserUrlButton,r,4);

    r=2;
    QPushButton* actionUrlButton = new QPushButton("Open Action URL", this);
       connect( actionUrlButton, SIGNAL( pressed()) , this, SLOT( actionUrlButtonPressed() ) );
    mainGrid->addWidget(actionUrlButton,r,4);

    r=3;
    QPushButton* notesUrlButton = new QPushButton("Open Notes URL", this);
       connect( notesUrlButton, SIGNAL( pressed()) , this, SLOT( notesUrlButtonPressed() ) );
    mainGrid->addWidget(notesUrlButton,r,4);

    r=4;
    QPushButton* logButton = new QPushButton("Open Log", this);
       connect( logButton, SIGNAL( pressed()) , this, SLOT( logButtonPressed() ) );
    mainGrid->addWidget(logButton,r,4);


    //Get overallstate
    //worst_service_state (18) + state (4)
    int overallState=jsonArray.at(18).toDouble()+jsonArray.at(4).toDouble();
    qDebug() << "overallState" << overallState;
    r=1;
    pcDialog = new PCDialog(Hostname, overallState, this);
    connect( pcDialog, SIGNAL(doubleClickedHost(QString)) , this, SLOT( slotDoubleClickedHost(QString) ) );
      mainGrid->addWidget(pcDialog,r,5,9,3);

      QJsonArray parentJsonArray=jsonArray.at(15).toArray();
     //pcDialog->setGeneration();
     for (int i=0;i<parentJsonArray.size();i++)
     {
         if (!parentJsonArray.at(i).toString().trimmed().isEmpty())
         {
           pcDialog->addParent(parentJsonArray.at(i).toString());
         }
     }

     //Childs (16)
     QJsonArray childJsonArray=jsonArray.at(16).toArray();
    //pcDialog->setGeneration();
    for (int i=0;i<childJsonArray.size();i++)
    {
        if (!childJsonArray.at(i).toString().trimmed().isEmpty())
        {
          pcDialog->addChild(childJsonArray.at(i).toString());
        }
    }

      r=0;
      QPushButton* getParentsButton = new QPushButton("Get Parents", this);
         connect( getParentsButton, SIGNAL( pressed()) , this, SLOT( requestParents() ) );
      mainGrid->addWidget(getParentsButton,r,5);

      QPushButton* forceButton = new QPushButton("Force", this);
         connect( forceButton, SIGNAL( pressed()) , pcDialog, SLOT( force() ) );
      mainGrid->addWidget(forceButton,r,6);

      mainGrid->addItem(new QSpacerItem ( 10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed ),r,7);
     //last spacer
       //mainGrid->addItem(new QSpacerItem ( 300, 0, QSizePolicy::Maximum, QSizePolicy::Fixed ),10,1,1,5);
       mainGrid->addItem(new QSpacerItem ( 500, 0, QSizePolicy::Expanding, QSizePolicy::Fixed ),10,5);



}
//slot
void KShortcutsEditorDelegate::itemActivated(QModelIndex index)
{
    //As per our constructor our parent *is* a QTreeWidget
    QTreeWidget *view = static_cast<QTreeWidget *>(parent());

    KShortcutsEditorItem *item = KShortcutsEditorPrivate::itemFromIndex(view, index);
    if (!item) {
        //that probably was a non-leaf (type() !=ActionItem) item
        return;
    }

    int column = index.column();
    if (column == Name) {
        // If user click in the name column activate the (Global|Local)Primary
        // column if possible.
        if (!view->header()->isSectionHidden(LocalPrimary)) {
            column = LocalPrimary;
        } else if (!view->header()->isSectionHidden(GlobalPrimary)) {
            column = GlobalPrimary;
        } else {
            // do nothing.
        }
        index = index.sibling(index.row(), column);
        view->selectionModel()->select(index, QItemSelectionModel::SelectCurrent);
    }

    // Check if the models wants us to edit the item at index
    if (!index.data(ShowExtensionIndicatorRole).value<bool>()) {
        return;
    }

    if (!isExtended(index)) {
        //we only want maximum ONE extender open at any time.
        if (m_editingIndex.isValid()) {
            KShortcutsEditorItem *oldItem = KShortcutsEditorPrivate::itemFromIndex(view,
                                            m_editingIndex);
            Q_ASSERT(oldItem); //here we really expect nothing but a real KShortcutsEditorItem

            oldItem->setNameBold(false);
            contractItem(m_editingIndex);
        }

        m_editingIndex = index;
        QWidget *viewport = static_cast<QAbstractItemView *>(parent())->viewport();

        if (column >= LocalPrimary && column <= GlobalAlternate) {
            ShortcutEditWidget *editor = new ShortcutEditWidget(viewport,
                    index.data(DefaultShortcutRole).value<QKeySequence>(),
                    index.data(ShortcutRole).value<QKeySequence>(),
                    m_allowLetterShortcuts);
            if (column == GlobalPrimary) {
                QObject *action = index.data(ObjectRole).value<QObject *>();
                editor->setAction(action);
                editor->setMultiKeyShortcutsAllowed(false);
                QString componentName = action->property("componentName").toString();
                if (componentName.isEmpty()) {
                    componentName = QCoreApplication::applicationName();
                }
                editor->setComponentName(componentName);
            }

            m_editor = editor;
            // For global shortcuts check against the kde standard shortcuts
            if (column == GlobalPrimary || column == GlobalAlternate) {
                editor->setCheckForConflictsAgainst(
                    KKeySequenceWidget::LocalShortcuts
                    | KKeySequenceWidget::GlobalShortcuts
                    | KKeySequenceWidget::StandardShortcuts);
            }

            editor->setCheckActionCollections(m_checkActionCollections);

            connect(m_editor, SIGNAL(keySequenceChanged(QKeySequence)),
                    this, SLOT(keySequenceChanged(QKeySequence)));
            connect(m_editor, SIGNAL(stealShortcut(QKeySequence,QAction*)),
                    this, SLOT(stealShortcut(QKeySequence,QAction*)));

        } else if (column == RockerGesture) {
예제 #9
0
SignatureDialog::SignatureDialog( const DigiDocSignature &signature, QWidget *parent )
:	QDialog( parent )
,	s( signature )
,	d( new SignatureDialogPrivate )
{
	d->setupUi( this );
	d->error->hide();
	setAttribute( Qt::WA_DeleteOnClose );

	const SslCertificate c = s.cert();
#define addCertButton(cert, button) if(!cert.isNull()) \
	d->buttonBox->addButton(button, QDialogButtonBox::ActionRole)->setProperty("cert", QVariant::fromValue(cert));
	addCertButton(s.cert(), tr("Show signer's certificate"));
	addCertButton(s.ocspCert(), tr("Show OCSP certificate"));
	addCertButton(s.tsaCert(), tr("Show TSA certificate"));
	addCertButton(qApp->confValue( Application::TSLCert ).value<QSslCertificate>(), tr("Show TSL certificate"));

	QString status;
	switch( s.validate() )
	{
	case DigiDocSignature::Valid:
		status = tr("Signature is valid");
		break;
	case DigiDocSignature::Warning:
		status = QString("%1 (%2)").arg( tr("Signature is valid"), tr("Warnings") );
		if( !s.lastError().isEmpty() )
			d->error->setPlainText( s.lastError() );
		if( s.warning() & DigiDocSignature::WrongNameSpace )
		{
			d->info->setText( tr(
				"This Digidoc document has not been created according to specification, "
				"but the digital signature is legally valid. Please inform the document creator "
				"of this issue. <a href='http://www.id.ee/?id=36511'>Additional information</a>.") );
		}
		if( s.warning() & DigiDocSignature::DigestWeak )
		{
			d->info->setText( tr(
				"The current BDOC container uses weaker encryption method than officialy accepted in Estonia.") );
		}
		break;
	case DigiDocSignature::Test:
		status = QString("%1 (%2)").arg( tr("Signature is valid"), tr("Test signature") );
		if( !s.lastError().isEmpty() )
			d->error->setPlainText( s.lastError() );
		d->info->setText( tr(
			"Test signature is signed with test certificates that are similar to the "
			"certificates of real tokens, but digital signatures with legal force cannot "
			"be given with them as there is no actual owner of the card. "
			"<a href='http://www.id.ee/index.php?id=30494'>Additional information</a>.") );
		break;
	case DigiDocSignature::Invalid:
		status = tr("Signature is not valid");
		d->error->setPlainText( s.lastError().isEmpty() ? tr("Unknown error") : s.lastError() );
		d->info->setText( tr(
			"This is an invalid signature or malformed digitally signed file. The signature is not valid.") );
		break;
	case DigiDocSignature::Unknown:
		status = tr("Signature status unknown");
		d->error->setPlainText( s.lastError().isEmpty() ? tr("Unknown error") : s.lastError() );
		d->info->setText( tr(
			"Signature status is displayed unknown if you don't have all validity confirmation service "
			"certificates and/or certificate authority certificates installed into your computer. "
			"<a href='http://www.id.ee/index.php?id=35941'>Additional information</a>.") );
		break;
	}
	if( d->error->toPlainText().isEmpty() && d->info->text().isEmpty() )
		d->tabWidget->removeTab( 0 );
	else
		d->buttonBox->addButton( QDialogButtonBox::Help );
	d->title->setText( c.toString( c.showCN() ? "CN serialNumber" : "GN SN serialNumber" ) + "\n" + status );
	setWindowTitle( c.toString( c.showCN() ? "CN serialNumber" : "GN SN serialNumber" ) + " - " + status );

	const QStringList l = s.locations();
	d->signerCity->setText( l.value( 0 ) );
	d->signerState->setText( l.value( 1 ) );
	d->signerZip->setText( l.value( 2 ) );
	d->signerCountry->setText( l.value( 3 ) );

	Q_FOREACH( const QString &role, s.roles() )
	{
		QLineEdit *line = new QLineEdit( role, d->signerRoleGroup );
		line->setReadOnly( true );
		d->signerRoleGroupLayout->addRow( line );
	}

	// Certificate info
	QTreeWidget *t = d->signatureView;
	t->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
	addItem( t, tr("TSL URL"), qApp->confValue( Application::TSLUrl ).toString() );
	addItem( t, tr("Signer's computer time (UTC)"), DateTime( s.signTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
	addItem( t, tr("Signature method"), s.signatureMethod() );
	addItem( t, tr("Container format"), s.parent()->mediaType() );
	if( s.type() != DigiDocSignature::DDocType )
		addItem( t, tr("Signature format"), s.profile() );
	if( !s.policy().isEmpty() )
	{
		#define toVer(X) (X)->toUInt() - 1
		QStringList ver = s.policy().split( "." );
		if( ver.size() >= 3 )
			addItem( t, tr("Signature policy"), QString("%1.%2.%3").arg( toVer(ver.end()-3) ).arg( toVer(ver.end()-2) ).arg( toVer(ver.end()-1) ) );
		else
			addItem( t, tr("Signature policy"), s.policy() );
	}
	addItem( t, tr("Signed file count"), QString::number( s.parent()->documentModel()->rowCount() ) );
	addItem( t, tr("Signer Certificate issuer"), c.issuerInfo( QSslCertificate::CommonName ) );
	if( !s.spuri().isEmpty() )
		addItem( t, "SPUri", s.spuri() );

	// OCSP info
	switch( s.type() )
	{
	case DigiDocSignature::TSType:
	{
		addItem( t, tr("Signature Timestamp"), DateTime( s.tsaTime().toLocalTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ));
		addItem( t, tr("Signature Timestamp") + " (UTC)", DateTime( s.tsaTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
		addItem( t, tr("TSA Certificate issuer"), SslCertificate(s.tsaCert()).issuerInfo( QSslCertificate::CommonName ) );
	} //Fall through to OCSP info
	case DigiDocSignature::DDocType:
	case DigiDocSignature::TMType:
	{
		SslCertificate ocsp = s.ocspCert();
		addItem( t, tr("OCSP Certificate issuer"), ocsp.issuerInfo( QSslCertificate::CommonName ) );
		addItem( t, tr("OCSP time"), DateTime( s.ocspTime().toLocalTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
		addItem( t, tr("OCSP time") + " (UTC)", DateTime( s.ocspTime() ).toStringZ( "dd.MM.yyyy hh:mm:ss" ) );
		addItem( t, tr("Hash value of signature"), SslCertificate::toHex( s.ocspNonce() ) );
		break;
	}
	default: break;
	}
}
예제 #10
0
void QtHelpers::GenAdjustWidgetAppearanceToOS(QWidget *rootWidget)
{
    if (rootWidget == NULL)
            return;

        QObject *child = NULL;
        QObjectList Containers;
        QObject *container  = NULL;
        QStringList DoNotAffect;

        // Make an exception list (Objects not to be affected)
        DoNotAffect.append("aboutTitleLabel");     // about Dialog
        DoNotAffect.append("aboutVersionLabel");   // about Dialog
        DoNotAffect.append("aboutCopyrightLabel"); // about Dialog
        DoNotAffect.append("aboutUrlLabel");       // about Dialog
        DoNotAffect.append("aboutLicenseLabel");   // about Dialog

        // Set sizes according to OS:
    #ifdef __APPLE__
        int ButtonHeight = 35;
        int cmbxHeight = 30;
        QFont cntrlFont("Myriad Pro", 14);
        QFont txtFont("Myriad Pro", 14);
    #elif _WIN32 // Win XP/7
        int ButtonHeight = 24;
        int cmbxHeight = 20;
        QFont cntrlFont("MS Shell Dlg 2", 8);
        QFont txtFont("MS Shell Dlg 2", 8);
    #else
        int ButtonHeight = 24;
        int cmbxHeight = 24;
        QFont cntrlFont("Ubuntu Condensed", 10);
        QFont txtFont("Ubuntu", 10);
    #endif

        // Append root to containers
        Containers.append(rootWidget);
        while (!Containers.isEmpty())
        {
            container = Containers.takeFirst();
            if (container != NULL)
            {
                for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++)
                {
                    child = container->children()[ChIdx];
                    if (!child->isWidgetType() || DoNotAffect.contains(child->objectName()))
                        continue;
                    // Append containers to Stack for recursion
                    if (child->children().size() > 0)
                        Containers.append(child);
                    else
                    {
                        // Cast child object to button and label
                        // (if the object is not of the correct type, it will be NULL)
                        QPushButton *button = qobject_cast<QPushButton *>(child);
                        QLabel *label = qobject_cast<QLabel *>(child);
                        QComboBox *cmbx = qobject_cast<QComboBox *>(child);
                        QLineEdit *ln = qobject_cast<QLineEdit *>(child);
                        QTreeWidget *tree = qobject_cast<QTreeWidget *>(child);
                        QPlainTextEdit *plain = qobject_cast<QPlainTextEdit *>(child);
                        QCheckBox *check = qobject_cast<QCheckBox *>(child);
                        if (button != NULL)
                        {
                            button->setMinimumHeight(ButtonHeight); // Win
                            button->setMaximumHeight(ButtonHeight); // Win
                            button->setFont(cntrlFont);
                        }
                        else if (cmbx != NULL)
                        {
                            cmbx->setFont(cntrlFont);
                            cmbx->setMaximumHeight(cmbxHeight);
                        }
                        else if (label != NULL)
                            label->setFont(txtFont);
                        else if (ln != NULL)
                            ln->setFont(txtFont);
                        else if (tree != NULL)
                        {
                            tree->header()->setFont(txtFont);
                        }
                        else if (plain != NULL)
                            plain->setFont(txtFont);
                        else if (check != NULL)
                            check->setFont(txtFont);
                    }
                }
            }
        }
}