Ejemplo n.º 1
0
ThoughtsDock::ThoughtsDock(QWidget *parent, Qt::WindowFlags flags)
    : BaseDock(parent, flags)
{
    setWindowTitle(tr("Thoughts"));
    setObjectName("dock_thoughts");
    setFeatures(QDockWidget::AllDockWidgetFeatures);
    setAllowedAreas(Qt::AllDockWidgetAreas);

    QWidget *w = new QWidget();
    QVBoxLayout *l = new QVBoxLayout();
    w->setLayout(l);

    // THOUGHTS TABLE
    tw_thoughts = new QTableWidget(this);
    tw_thoughts->setColumnCount(3);
    tw_thoughts->setEditTriggers(QTableWidget::NoEditTriggers);
    tw_thoughts->setWordWrap(true);
    tw_thoughts->setShowGrid(false);
    tw_thoughts->setGridStyle(Qt::NoPen);
    tw_thoughts->setAlternatingRowColors(true);
    tw_thoughts->setSelectionMode(QAbstractItemView::ExtendedSelection);
    tw_thoughts->setSelectionBehavior(QAbstractItemView::SelectRows);
    tw_thoughts->setHorizontalHeaderLabels(QStringList() << "Thought" << "Count" << "Description");
    tw_thoughts->verticalHeader()->hide();
    tw_thoughts->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
    tw_thoughts->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Interactive);
    tw_thoughts->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Interactive);
    tw_thoughts->setColumnWidth(0,100);
    tw_thoughts->setColumnWidth(1,50);
    tw_thoughts->horizontalHeader()->setStretchLastSection(true);

    QHBoxLayout *s = new QHBoxLayout();
    QLabel *lbl_search = new QLabel("Search",this);
    s->addWidget(lbl_search);
    QLineEdit *le_search = new QLineEdit(this);
    le_search->setObjectName("le_search");
    s->addWidget(le_search);
    QPushButton *btn_clear_search = new QPushButton(this);
    QIcon icn(":img/cross.png");
    btn_clear_search->setIcon(icn);
    s->addWidget(btn_clear_search);
    l->addLayout(s);

    QPushButton *btn = new QPushButton("Clear Filter",this);
    w->layout()->addWidget(tw_thoughts);
    w->layout()->addWidget(btn);

    setWidget(w);

    connect(tw_thoughts,SIGNAL(itemSelectionChanged()),this,SLOT(selection_changed()));
    connect(btn, SIGNAL(clicked()),this,SLOT(clear_filter()));
    connect(le_search, SIGNAL(textChanged(QString)),this, SLOT(search_changed(QString)));
    connect(btn_clear_search, SIGNAL(clicked()),this,SLOT(clear_search()));
}
Ejemplo n.º 2
0
static QIcon readIconFrom(const QByteArray& path, const QByteArray& iconname, int depth = 0)
{
    if (path.isEmpty() || depth > MAX_ICON_RECURSE_DEPTH)
        return QIcon();

    QByteArray fn;
    static const char* exts[] = { ".xpm", ".png", 0 };
    for (int i = 0; ; ++i) {
        if (!exts[i])
            break;
        fn = path + iconname + exts[i];
        if (QFile::exists(QString::fromLocal8Bit(fn.constData(), fn.size()))) {
            QIcon icn(QString::fromLocal8Bit(fn.constData(), fn.size()));
            return icn;
        }
    }

    QIcon icn;
    DIR *dir = opendir(path.constData());
    if (!dir)
        return QIcon();
    struct dirent d, *res;
    while (readdir_r(dir, &d, &res) == 0 && res != 0) {
        if (d.d_type == DT_DIR) {
            if (strcmp(d.d_name, ".") && strcmp(d.d_name, "..")) {
                icn = readIconFrom(path + QByteArray(d.d_name) + '/', iconname, depth + 1);
                if (!icn.isNull()) {
                    closedir(dir);
                    return icn;
                }
            }
        }
    }

    closedir(dir);

    return QIcon();
}