// ! [2] private void browse() { String directory = QFileDialog.getExistingDirectory(this, tr("Find Files"), QDir.currentPath()); if (!directory.equals("")) { directoryComboBox.addItem(directory); directoryComboBox.setCurrentIndex(directoryComboBox.currentIndex() + 1); } }
// ! [10] private QComboBox createComboBox(String text) { QComboBox comboBox = new QComboBox(); comboBox.setEditable(true); comboBox.addItem(text); comboBox.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred); return comboBox; }
// ! [3] private void createControls(String title) { controlsGroup = new QGroupBox(title); minimumLabel = new QLabel(tr("Minimum value:")); maximumLabel = new QLabel(tr("Maximum value:")); valueLabel = new QLabel(tr("Current value:")); invertedAppearance = new QCheckBox(tr("Inverted appearance")); invertedKeyBindings = new QCheckBox(tr("Inverted key bindings")); // ! [3] //! [4] minimumSpinBox = new QSpinBox(); // ! [4] //! [5] minimumSpinBox.setRange(-100, 100); minimumSpinBox.setSingleStep(1); maximumSpinBox = new QSpinBox(); maximumSpinBox.setRange(-100, 100); maximumSpinBox.setSingleStep(1); valueSpinBox = new QSpinBox(); valueSpinBox.setRange(-100, 100); valueSpinBox.setSingleStep(1); orientationCombo = new QComboBox(); orientationCombo.addItem(tr("Horizontal slider-like widgets")); orientationCombo.addItem(tr("Vertical slider-like widgets")); // ! [5] //! [6] orientationCombo.activatedIndex.connect(stackedWidget, "setCurrentIndex(int)"); // ! [6] //! [7] minimumSpinBox.valueChanged.connect(horizontalSliders, "setMinimum(int)"); minimumSpinBox.valueChanged.connect(verticalSliders, "setMinimum(int)"); maximumSpinBox.valueChanged.connect(horizontalSliders, "setMaximum(int)"); maximumSpinBox.valueChanged.connect(verticalSliders, "setMaximum(int)"); invertedAppearance.toggled.connect(horizontalSliders, "invertAppearance(boolean)"); invertedAppearance.toggled.connect(verticalSliders, "invertAppearance(boolean)"); invertedKeyBindings.toggled.connect(horizontalSliders, "invertedKeyBindings(boolean)"); invertedKeyBindings.toggled.connect(verticalSliders, "invertedKeyBindings(boolean)"); QGridLayout controlsLayout = new QGridLayout(); controlsLayout.addWidget(minimumLabel, 0, 0); controlsLayout.addWidget(maximumLabel, 1, 0); controlsLayout.addWidget(valueLabel, 2, 0); controlsLayout.addWidget(minimumSpinBox, 0, 1); controlsLayout.addWidget(maximumSpinBox, 1, 1); controlsLayout.addWidget(valueSpinBox, 2, 1); controlsLayout.addWidget(invertedAppearance, 0, 2); controlsLayout.addWidget(invertedKeyBindings, 1, 2); controlsLayout.addWidget(orientationCombo, 3, 0, 1, 3); controlsGroup.setLayout(controlsLayout); }
// ! [3] private void find() { filesTable.setRowCount(0); String fileName = fileComboBox.currentText(); String text = textComboBox.currentText(); String path = directoryComboBox.currentText(); // ! [3] // ! [4] QDir directory = new QDir(path); List<String> files = new LinkedList<String>(); if (fileName.equals("")) fileName = "*"; List<String> entries = new LinkedList<String>(); entries.add(fileName); files = directory.entryList(entries, new QDir.Filters(QDir.Filter.Files, QDir.Filter.NoSymLinks)); if (!text.equals("")) files = findFiles(directory, files, text); showFiles(directory, files); }