CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) : SyntaxLineEdit(parent), plain_(plain), field_name_only_(false), enable_save_action_(false), save_action_(NULL), remove_action_(NULL), bookmark_button_(NULL), clear_button_(NULL), apply_button_(NULL) { setAccessibleName(tr("Capture filter entry")); completion_model_ = new QStringListModel(this); setCompleter(new QCompleter(completion_model_, this)); setCompletionTokenChars(libpcap_primitive_chars_); setConflict(false); if (!plain_) { bookmark_button_ = new StockIconToolButton(this, "x-capture-filter-bookmark"); bookmark_button_->setCursor(Qt::ArrowCursor); bookmark_button_->setMenu(new QMenu()); bookmark_button_->setPopupMode(QToolButton::InstantPopup); bookmark_button_->setToolTip(tr("Manage saved bookmarks.")); bookmark_button_->setIconSize(QSize(14, 14)); bookmark_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" "QToolButton::menu-indicator { image: none; }" ); connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked())); } if (!plain_) { clear_button_ = new StockIconToolButton(this, "x-filter-clear"); clear_button_->setCursor(Qt::ArrowCursor); clear_button_->setToolTip(QString()); clear_button_->setIconSize(QSize(14, 14)); clear_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" " margin-left: 1px;" "}" ); connect(clear_button_, SIGNAL(clicked()), this, SLOT(clearFilter())); } connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&))); #if 0 // Disable the apply button for now if (!plain_) { apply_button_ = new StockIconToolButton(this, "x-filter-apply"); apply_button_->setCursor(Qt::ArrowCursor); apply_button_->setEnabled(false); apply_button_->setToolTip(tr("Apply this filter string to the display.")); apply_button_->setIconSize(QSize(24, 14)); apply_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" ); connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter())); } #endif connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter())); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QSize bksz; if (bookmark_button_) bksz = bookmark_button_->sizeHint(); QSize cbsz; if (clear_button_) cbsz = clear_button_->sizeHint(); QSize apsz; if (apply_button_) apsz = apply_button_->sizeHint(); setStyleSheet(QString( "CaptureFilterEdit {" " padding-left: %1px;" " margin-left: %2px;" " margin-right: %3px;" "}" ) .arg(frameWidth + 1) .arg(bksz.width()) .arg(cbsz.width() + apsz.width() + frameWidth + 1) ); QComboBox *cf_combo = qobject_cast<QComboBox *>(parent); if (cf_combo) { connect(cf_combo, SIGNAL(activated(QString)), this, SIGNAL(textEdited(QString))); } QThread *syntax_thread = new QThread; syntax_worker_ = new CaptureFilterSyntaxWorker; syntax_worker_->moveToThread(syntax_thread); connect(wsApp, SIGNAL(appInitialized()), this, SLOT(updateBookmarkMenu())); connect(wsApp, SIGNAL(captureFilterListChanged()), this, SLOT(updateBookmarkMenu())); connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start())); connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter())); connect(syntax_worker_, SIGNAL(syntaxResult(QString,int,QString)), this, SLOT(setFilterSyntaxState(QString,int,QString))); connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater())); syntax_thread->start(); }
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) : SyntaxLineEdit(parent), plain_(plain), field_name_only_(false), bookmark_button_(NULL), clear_button_(NULL), apply_button_(NULL) { setAccessibleName(tr("Capture filter entry")); completion_model_ = new QStringListModel(this); setCompleter(new QCompleter(completion_model_, this)); setCompletionTokenChars(libpcap_primitive_chars_); placeholder_text_ = QString(tr("Enter a capture filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS); #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) setPlaceholderText(placeholder_text_); #endif // These are fully implemented in DisplayFilterEdit but not here. if (!plain_) { bookmark_button_ = new StockIconToolButton(this, "x-filter-bookmark"); bookmark_button_->setCursor(Qt::ArrowCursor); bookmark_button_->setPopupMode(QToolButton::InstantPopup); bookmark_button_->setToolTip(tr("Manage saved bookmarks.")); bookmark_button_->setIconSize(QSize(14, 14)); bookmark_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" "QToolButton::menu-indicator { image: none; }" ); connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked())); } if (!plain_) { clear_button_ = new StockIconToolButton(this, "x-filter-clear"); clear_button_->setCursor(Qt::ArrowCursor); clear_button_->setToolTip(QString()); clear_button_->setIconSize(QSize(14, 14)); clear_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" " margin-left: 1px;" "}" ); connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear())); } connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&))); if (!plain_) { apply_button_ = new StockIconToolButton(this, "x-filter-apply"); apply_button_->setCursor(Qt::ArrowCursor); apply_button_->setEnabled(false); apply_button_->setToolTip(tr("Apply this filter string to the display.")); apply_button_->setIconSize(QSize(24, 14)); apply_button_->setStyleSheet( "QToolButton {" " border: none;" " background: transparent;" // Disables platform style on Windows. " padding: 0 0 0 0;" "}" ); connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter())); connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter())); } int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QSize bksz; if (bookmark_button_) bksz = bookmark_button_->sizeHint(); QSize cbsz; if (clear_button_) cbsz = clear_button_->sizeHint(); QSize apsz; if (apply_button_) apsz = apply_button_->sizeHint(); setStyleSheet(QString( "CaptureFilterEdit {" " padding-left: %1px;" " margin-left: %2px;" " margin-right: %3px;" "}" ) .arg(frameWidth + 1) .arg(bksz.width()) .arg(cbsz.width() + apsz.width() + frameWidth + 1) ); QThread *syntax_thread = new QThread; syntax_worker_ = new CaptureFilterSyntaxWorker; syntax_worker_->moveToThread(syntax_thread); connect(wsApp, SIGNAL(appInitialized()), this, SLOT(initCaptureFilter())); connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start())); connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter())); connect(syntax_worker_, SIGNAL(syntaxResult(QString,bool,QString)), this, SLOT(setFilterSyntaxState(QString,bool,QString))); connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater())); syntax_thread->start(); checkFilter(); }
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) : SyntaxLineEdit(parent), plain_(plain), field_name_only_(false), apply_button_(NULL) { setAccessibleName(tr("Capture filter entry")); completion_model_ = new QStringListModel(this); setCompleter(new QCompleter(completion_model_, this)); setCompletionTokenChars(libpcap_primitive_chars_); placeholder_text_ = QString(tr("Enter a capture filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS); #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) setPlaceholderText(placeholder_text_); #endif // DFCombo // Bookmark (star) // DispalyFilterEdit // Clear button // Apply (right arrow) + Cancel (x) + Reload (arrowed circle) // Combo drop-down // XXX - Move bookmark and apply buttons to the toolbar a la Firefox, Chrome & Safari? // XXX - Use native buttons on OS X? bookmark_button_ = new QToolButton(this); bookmark_button_->setCursor(Qt::ArrowCursor); bookmark_button_->setStyleSheet(QString( "QToolButton { /* all types of tool button */" " border 0 0 0 0;" #ifdef Q_OS_MAC " border-right: %1px solid gray;" #else " border-right: %1px solid palette(shadow);" #endif " border-top-left-radius: 3px;" " border-bottom-left-radius: 3px;" " padding-left: 1px;" " image: url(:/dfilter/dfilter_bookmark_normal.png) center;" "}" "QToolButton:hover {" " image: url(:/dfilter/dfilter_bookmark_hover.png) center;" "}" "QToolButton:pressed {" " image: url(:/dfilter/dfilter_bookmark_pressed.png) center;" "}" "QToolButton:disabled {" " image: url(:/dfilter/dfilter_bookmark_disabled.png) center;" "}" ).arg(plain_ ? 0 : 1) ); connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked())); clear_button_ = new QToolButton(this); clear_button_->setCursor(Qt::ArrowCursor); clear_button_->setStyleSheet( "QToolButton {" " image: url(:/dfilter/dfilter_erase_normal.png) center;" " border: none;" " width: 16px;" "}" "QToolButton:hover {" " image: url(:/dfilter/dfilter_erase_active.png) center;" "}" "QToolButton:pressed {" " image: url(:/dfilter/dfilter_erase_selected.png) center;" "}" ); clear_button_->hide(); connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear())); connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&))); if (!plain_) { apply_button_ = new QToolButton(this); apply_button_->setCursor(Qt::ArrowCursor); apply_button_->setEnabled(false); apply_button_->setStyleSheet( "QToolButton { /* all types of tool button */" " border 0 0 0 0;" " border-top-right-radius: 3px;" " border-bottom-right-radius: 3px;" " padding-right: 1px;" " image: url(:/dfilter/dfilter_apply_normal.png) center;" "}" "QToolButton:hover {" " image: url(:/dfilter/dfilter_apply_hover.png) center;" "}" "QToolButton:pressed {" " image: url(:/dfilter/dfilter_apply_pressed.png) center;" "}" "QToolButton:disabled {" " image: url(:/dfilter/dfilter_apply_disabled.png) center;" "}" ); connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter())); connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter())); } int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); QSize bksz = bookmark_button_->sizeHint(); QSize cbsz = clear_button_->sizeHint(); QSize apsz; if (apply_button_) { apsz = apply_button_->sizeHint(); } else { apsz.setHeight(0); apsz.setWidth(0); } setStyleSheet(QString( "CaptureFilterEdit {" " padding-left: %1px;" " margin-left: %2px;" " margin-right: %3px;" "}" ) .arg(frameWidth + 1) .arg(bksz.width()) .arg(cbsz.width() + apsz.width() + frameWidth + 1) ); QThread *syntax_thread = new QThread; syntax_worker_ = new CaptureFilterSyntaxWorker; syntax_worker_->moveToThread(syntax_thread); connect(wsApp, SIGNAL(appInitialized()), this, SLOT(initCaptureFilter())); connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start())); connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter())); connect(syntax_worker_, SIGNAL(syntaxResult(QString,bool,QString)), this, SLOT(setFilterSyntaxState(QString,bool,QString))); connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater())); syntax_thread->start(); }