3 Minimum Profit - Programmer Text Editor
7 Copyright (C) 2009 Angel Ortega <angel@triptico.com>
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 http://www.triptico.com
27 /* override auto-generated definition in config.h */
28 extern "C" int qt4_drv_detect(int * argc
, char *** argv
);
44 class MPWindow
: public QMainWindow
47 MPWindow(QWidget
*parent
= 0);
49 bool event(QEvent
*event
);
54 class MPArea
: public QWidget
59 MPArea(QWidget
*parent
= 0);
60 void inputMethodEvent(QInputMethodEvent
*event
);
61 void keyPressEvent(QKeyEvent
*event
);
62 void keyReleaseEvent(QKeyEvent
*event
);
63 void mousePressEvent(QMouseEvent
*event
);
64 void mouseReleaseEvent(QMouseEvent
*event
);
65 void mouseMoveEvent(QMouseEvent
*event
);
66 void wheelEvent(QWheelEvent
*event
);
67 void dragEnterEvent(QDragEnterEvent
*event
);
68 void dropEvent(QDropEvent
*event
);
69 bool event(QEvent
*event
);
72 void paintEvent(QPaintEvent
*event
);
75 void from_scrollbar(int);
76 void from_filetabs(int);
77 void from_menu(QAction
*);
84 //QStatusBar *statusbar;
88 #define MENU_CLASS QMenu
90 #include "mpv_qk_common.cpp"
92 static void draw_status(void)
94 statusbar
->setText(str_to_qstring(mp_build_status_line()));
98 /** MPWindow methods **/
100 MPWindow::MPWindow(QWidget
*parent
) : QMainWindow(parent
)
102 setWindowTitle("mp-5");
104 menubar
= this->menuBar();
107 statusbar
= new QLabel();
108 this->statusBar()->addWidget(statusbar
);
110 /* the full container */
111 QVBoxLayout
*vb
= new QVBoxLayout();
113 file_tabs
= new QTabBar();
114 file_tabs
->setFocusPolicy(Qt::NoFocus
);
116 QHBoxLayout
*hb
= new QHBoxLayout();
120 scrollbar
= new QScrollBar();
121 scrollbar
->setFocusPolicy(Qt::NoFocus
);
124 hb
->addWidget(scrollbar
);
125 QWidget
*cc
= new QWidget();
128 vb
->addWidget(file_tabs
);
130 QWidget
*mc
= new QWidget();
133 setCentralWidget(mc
);
135 connect(scrollbar
, SIGNAL(valueChanged(int)),
136 area
, SLOT(from_scrollbar(int)));
138 connect(file_tabs
, SIGNAL(currentChanged(int)),
139 area
, SLOT(from_filetabs(int)));
141 connect(menubar
, SIGNAL(triggered(QAction
*)),
142 area
, SLOT(from_menu(QAction
*)));
144 this->setWindowIcon(QIcon(QPixmap(mp_xpm
)));
146 settings
= new QSettings("triptico.com", "MinimumProfit");
148 QPoint pos
= settings
->value("pos", QPoint(20, 20)).toPoint();
149 QSize size
= settings
->value("size", QSize(600, 400)).toSize();
156 static void save_settings(MPWindow
*w
)
158 w
->settings
->setValue("pos", w
->pos());
159 w
->settings
->setValue("size", w
->size());
164 bool MPWindow::queryExit(void)
166 mp_process_event(MPDM_LS(L
"close-window"));
170 return mp_exit_requested
? true : false;
174 bool MPWindow::event(QEvent
*event
)
176 /* do the processing */
177 bool r
= QWidget::event(event
);
179 if (mp_exit_requested
) {
188 /** driver functions **/
190 static mpdm_t
qt4_drv_alert(mpdm_t a
)
193 QMessageBox::information(0, "mp " VERSION
, str_to_qstring(mpdm_aget(a
, 0)));
199 static mpdm_t
qt4_drv_confirm(mpdm_t a
)
204 r
= QMessageBox::question(0, "mp" VERSION
,
205 str_to_qstring(mpdm_aget(a
, 0)),
206 QMessageBox::Yes
| QMessageBox::No
| QMessageBox::Cancel
210 case QMessageBox::Yes
:
214 case QMessageBox::No
:
218 case QMessageBox::Cancel
:
227 static mpdm_t
qt4_drv_openfile(mpdm_t a
)
232 getcwd(tmp
, sizeof(tmp
));
235 r
= QFileDialog::getOpenFileName(window
,
236 str_to_qstring(mpdm_aget(a
, 0)), tmp
);
238 return qstring_to_str(r
);
242 static mpdm_t
qt4_drv_savefile(mpdm_t a
)
247 getcwd(tmp
, sizeof(tmp
));
250 r
= QFileDialog::getSaveFileName(window
,
251 str_to_qstring(mpdm_aget(a
, 0)), tmp
);
253 return qstring_to_str(r
);
257 class MPForm
: public QDialog
260 QDialogButtonBox
*button_box
;
262 MPForm(QWidget
*parent
= 0) : QDialog(parent
)
264 button_box
= new QDialogButtonBox(QDialogButtonBox::Ok
|
265 QDialogButtonBox::Cancel
);
267 connect(button_box
, SIGNAL(accepted()), this, SLOT(accept()));
268 connect(button_box
, SIGNAL(rejected()), this, SLOT(reject()));
273 static mpdm_t
qt4_drv_form(mpdm_t a
)
280 MPForm
*dialog
= new MPForm(window
);
281 dialog
->setWindowTitle("mp " VERSION
);
283 dialog
->setModal(true);
285 widget_list
= mpdm_aget(a
, 0);
287 QWidget
*form
= new QWidget();
288 QFormLayout
*fl
= new QFormLayout();
290 for (n
= 0; n
< mpdm_size(widget_list
); n
++) {
291 mpdm_t w
= mpdm_aget(widget_list
, n
);
294 QLabel
*ql
= new QLabel("");
296 type
= mpdm_string(mpdm_hget_s(w
, L
"type"));
298 if ((t
= mpdm_hget_s(w
, L
"label")) != NULL
) {
299 ql
->setText(str_to_qstring(mpdm_gettext(t
)));
302 t
= mpdm_hget_s(w
, L
"value");
304 if (wcscmp(type
, L
"text") == 0) {
306 QComboBox
*qc
= new QComboBox();
308 qc
->setEditable(true);
309 qc
->setMinimumContentsLength(30);
310 qc
->setMaxVisibleItems(8);
313 qc
->setEditText(str_to_qstring(t
));
317 if ((h
= mpdm_hget_s(w
, L
"history")) != NULL
) {
320 /* has history; fill it */
321 h
= mp_get_history(h
);
323 for (i
= mpdm_size(h
) - 1; i
>= 0; i
--)
324 qc
->addItem(str_to_qstring(mpdm_aget(h
, i
)));
330 if (wcscmp(type
, L
"password") == 0) {
331 QLineEdit
*qe
= new QLineEdit();
333 qe
->setEchoMode(QLineEdit::Password
);
340 if (wcscmp(type
, L
"checkbox") == 0) {
341 QCheckBox
*qc
= new QCheckBox();
344 qc
->setCheckState(Qt::Checked
);
351 if (wcscmp(type
, L
"list") == 0) {
353 QListWidget
*qlw
= new QListWidget();
354 qlw
->setMinimumWidth(480);
356 /* use a monospaced font */
357 qlw
->setFont(QFont(QString("Mono")));
359 mpdm_t l
= mpdm_hget_s(w
, L
"list");
361 for (i
= 0; i
< mpdm_size(l
); i
++)
362 qlw
->addItem(str_to_qstring(mpdm_aget(l
, i
)));
364 qlw
->setCurrentRow(mpdm_ival(t
));
372 qlist
[n
]->setFocus(Qt::OtherFocusReason
);
377 QVBoxLayout
*ml
= new QVBoxLayout();
379 ml
->addWidget(dialog
->button_box
);
381 dialog
->setLayout(ml
);
388 r
= MPDM_A(mpdm_size(widget_list
));
390 /* fill the return values */
391 for (n
= 0; n
< mpdm_size(widget_list
); n
++) {
392 mpdm_t w
= mpdm_aget(widget_list
, n
);
396 type
= mpdm_string(mpdm_hget_s(w
, L
"type"));
398 if (wcscmp(type
, L
"text") == 0) {
400 QComboBox
*ql
= (QComboBox
*)qlist
[n
];
402 v
= qstring_to_str(ql
->currentText());
404 /* if it has history, add to it */
405 if ((h
= mpdm_hget_s(w
, L
"history")) != NULL
&&
406 v
!= NULL
&& mpdm_cmp(v
, MPDM_LS(L
"")) != 0) {
407 h
= mp_get_history(h
);
409 if (mpdm_cmp(v
, mpdm_aget(h
, -1)) != 0)
414 if (wcscmp(type
, L
"password") == 0) {
415 QLineEdit
*ql
= (QLineEdit
*)qlist
[n
];
417 v
= qstring_to_str(ql
->text());
420 if (wcscmp(type
, L
"checkbox") == 0) {
421 QCheckBox
*qb
= (QCheckBox
*)qlist
[n
];
423 v
= MPDM_I(qb
->checkState() == Qt::Checked
);
426 if (wcscmp(type
, L
"list") == 0) {
427 QListWidget
*ql
= (QListWidget
*)qlist
[n
];
429 v
= MPDM_I(ql
->currentRow());
439 static void register_functions(void)
443 drv
= mpdm_hget_s(mp
, L
"drv");
444 mpdm_hset_s(drv
, L
"main_loop", MPDM_X(qt4_drv_main_loop
));
445 mpdm_hset_s(drv
, L
"shutdown", MPDM_X(qt4_drv_shutdown
));
447 mpdm_hset_s(drv
, L
"clip_to_sys", MPDM_X(qt4_drv_clip_to_sys
));
448 mpdm_hset_s(drv
, L
"sys_to_clip", MPDM_X(qt4_drv_sys_to_clip
));
449 mpdm_hset_s(drv
, L
"update_ui", MPDM_X(qt4_drv_update_ui
));
450 /* mpdm_hset_s(drv, L"timer", MPDM_X(qt4_drv_timer));*/
451 mpdm_hset_s(drv
, L
"busy", MPDM_X(qt4_drv_busy
));
453 mpdm_hset_s(drv
, L
"alert", MPDM_X(qt4_drv_alert
));
454 mpdm_hset_s(drv
, L
"confirm", MPDM_X(qt4_drv_confirm
));
455 mpdm_hset_s(drv
, L
"openfile", MPDM_X(qt4_drv_openfile
));
456 mpdm_hset_s(drv
, L
"savefile", MPDM_X(qt4_drv_savefile
));
457 mpdm_hset_s(drv
, L
"form", MPDM_X(qt4_drv_form
));
461 static mpdm_t
qt4_drv_startup(mpdm_t a
)
462 /* driver initialization */
464 register_functions();
469 window
= new MPWindow();
475 extern "C" Display
*XOpenDisplay(char *);
477 extern "C" int qt4_drv_detect(int * argc
, char *** argv
)
480 Display
*x11_display
;
482 /* try connecting directly to the Xserver */
483 if ((x11_display
= XOpenDisplay((char *)NULL
)) == NULL
)
486 /* this is where it crashes if no X server */
487 app
= new QApplication(x11_display
);
489 drv
= mpdm_hget_s(mp
, L
"drv");
490 mpdm_hset_s(drv
, L
"id", MPDM_LS(L
"qt4"));
491 mpdm_hset_s(drv
, L
"startup", MPDM_X(qt4_drv_startup
));
496 #include "mpv_qt4.moc"