Trash::Trash() { m_trash = g_file_new_for_uri(TRASH_URI); setShortcutKey(Qt::Key_T); updateTrashIcon(); startMonitoringTrash(); m_nautilusIface = new QDBusInterface("org.gnome.Nautilus", "/org/gnome/Nautilus", "org.gnome.Nautilus.FileOperations", QDBusConnection::sessionBus(), this); }
void DShortcutEdit::shortcutKeyPress(QKeyEvent *e) { //qDebug() << e->key() << e->text() << e->count() << Qt::CTRL << e->nativeScanCode() << e->nativeVirtualKey(); m_shortcutKeys.clear(); int state = 0; if ((e->modifiers() & Qt::ShiftModifier) && (e->text().isEmpty() || !e->text().at(0).isPrint() || e->text().at(0).isLetterOrNumber() || e->text().at(0).isSpace())) state |= Qt::SHIFT; if (e->modifiers() & Qt::ControlModifier) state |= Qt::CTRL; if (e->modifiers() & Qt::MetaModifier) state |= Qt::META; if (e->modifiers() & Qt::AltModifier) state |= Qt::ALT; int key = e->key() | state; qDebug() << "keys: " << QKeySequence(key, 0, 0, 0).toString(QKeySequence::NativeText); m_shortcutKeys = QKeySequence(key, 0, 0, 0).toString(QKeySequence::NativeText); //qDebug() << m_shortcutKeys << e->text() << e->key(); //qDebug() << "keys: " << int(e->key() & ~(Qt::SHIFT | Qt::ControlModifier | Qt::META | Qt::ALT)); // if pressed key is "Backspace", its means "clear all" if (m_shortcutKeys == "Backspace") return clearShortcutKey(); setShortcutKey(m_shortcutKeys); QString lastKey = m_shortcutKeys.split("+").last(); qDebug() << "last: " << lastKey << lastKey.size(); // if lastKey is not alt, shift, ctrl, meta, shortcut key is finished. if (lastKey.size() == 2 && !lastKey.at(0).isLetter()) return; if (lastKey != "Meta" && lastKey != "Ctrl" && lastKey != "Shift" && lastKey != "Alt") toEchoMode(); }
DShortcutEdit::DShortcutEdit(QWidget *parent) : QFrame(parent) { D_THEME_INIT_WIDGET(DShortcutEdit); m_keysEdit = new QLabel(DefaultTips); m_keysEdit->setObjectName("Edit"); m_keysEdit->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); m_keysEdit->installEventFilter(this); m_keysEdit->setFocusPolicy(Qt::StrongFocus); m_keysEdit->hide(); m_keysLabel = new DShortcutEditLabel; m_keysLabel->setObjectName("Label"); m_keysLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); m_keysLabel->installEventFilter(this); m_keysLabel->setFocusPolicy(Qt::NoFocus); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(m_keysEdit); layout->addWidget(m_keysLabel); layout->setSpacing(0); layout->setMargin(0); setLayout(layout); setFocusPolicy(Qt::NoFocus); // Meta+Ctrl+Alt+Shift+Backspace is longest shortcut keys setMinimumWidth(180); #ifdef QT_DEBUG // for test setShortcutKey("Meta+Ctrl+Alt+Shift+Backspace"); #endif m_keyMapping.insert("PgDown", "PageDown"); m_keyMapping.insert("PgUp", "PageUp"); m_blockedShortcutKeys.append(QRegExp("^Backspace$")); //connect(this, &DShortcutEdit::invalidShortcutKey, [this] () -> void {m_keysLabel->setEchoState(DShortcutEditLabel::Invalid);}); }
void DShortcutEdit::clearShortcutKey() { setShortcutKey(QString()); }