QWidget* qt_tm_embedded_widget_rep::as_qwidget() { qwid = new QWidget(); QVBoxLayout* l = new QVBoxLayout(); l->setContentsMargins (0,0,0,0); qwid->setLayout (l); l->addWidget (concrete(main_widget)->as_qwidget()); return qwid; }
qt_popup_widget_rep::qt_popup_widget_rep (widget wid, command _quit) : qt_widget_rep(qt_widget_rep::popup_widget, 0), quit(_quit) { qwid = new QTMPopupWidget(concrete(wid)->as_qwidget()); if (qwid->metaObject() -> indexOfSignal (QMetaObject::normalizedSignature ("closed()").constData ()) != -1) { QTMCommand* qtmcmd = new QTMCommand(qwid, quit); QObject::connect(qwid, SIGNAL (closed()), qtmcmd, SLOT (apply())); } }
int main(int argc, const char *argv[]) { FILELog::ReportingLevel() = FILELog::FromString("ERROR"); char* agent_file = "../agents/constmoveagent"; char* data_file = "../data/37subjects.csvSUB0.csv"; int player=0; double params [] = {0.1,0.2,0,1,1,1,1,1,3,4}; double* paramptr= params; data_struct dat = load_data(dat,std::string(data_file)); std::string times_file=dat.get_times_file(data_file); Agent_params ap = read_agent_params(std::string(agent_file)); concrete(ap,paramptr); for (properties::iterator i = ap.m_properties.begin(); i != ap.m_properties.end(); ++i) { assert(!is_concrete_param(i->second)); } char output[]="Output/out.txt"; std::cout<<compute_loglik_agent(ap,dat,false,player,/*not-used*/0,times_file,output); return 0; }
void mexFunction(int /*nlhs*/, mxArray *plhs[],int /*nrhs*/, const mxArray *prhs[]){ FILELog::ReportingLevel() = FILELog::FromString("ERROR"); //FILELog::ReportingLevel() = FILELog::FromString("DEBUG"); FILE_LOG(logDEBUG) << " Starting mexFunction" << std::endl; double* playerptr=mxGetPr(prhs[0]); FILE_LOG(logDEBUG) << "playerptr " << std::endl; char* agent_file =mxArrayToString(prhs[1]); FILE_LOG(logDEBUG) << "2 " << std::endl; char* data_file =mxArrayToString(prhs[2]); FILE_LOG(logDEBUG) << "3 " << std::endl; double* paramptr=mxGetPr(prhs[3]); FILE_LOG(logDEBUG) << "4 " << std::endl; int player=((int) (*playerptr)); FILE_LOG(logDEBUG) << "5 " << std::endl; //std::ostringstream s,s2; //s << "/home/zb9/mnk/agents/bfsagent" << player; //std::string agent_file(agent_file); //s2 << "/home/zb9/mnk/data/37subjects.csvSUB" << player << "train.csv"; //std::string data_file (std::string(data_file)); FILE_LOG(logDEBUG) << "Loading from data file: "<< data_file << std::endl; data_struct dat; dat = load_data(dat,std::string(data_file)); //TODO: Filter by subject (here it's player) FILE_LOG(logDEBUG) << "Getting times file " << std::endl; std::string times_file=dat.get_times_file(data_file); FILE_LOG(logDEBUG) << "7 " << std::endl; Agent_params ap = read_agent_params(std::string(agent_file)); FILE_LOG(logDEBUG) << " Freeing memory "<<agent_file << std::endl; mxFree(agent_file); mxFree(data_file); FILE_LOG(logDEBUG) << " Starting concrete process for "<<agent_file << std::endl; concrete(ap,paramptr); for (properties::iterator i = ap.m_properties.begin(); i != ap.m_properties.end(); ++i) { assert(!is_concrete_param(i->second)); } char output[]="Output/out.txt"; FILE_LOG(logDEBUG) << " Calling compute_loglik_agent" << std::endl; plhs[0] = mxCreateDoubleScalar(compute_loglik_agent(ap,dat,false,player,/*not-used*/0,times_file,output)); FILE_LOG(logDEBUG) << " Returning from mexFunction" << std::endl; }
qt_tm_widget_rep::qt_tm_widget_rep(int mask, command _quit) : qt_window_widget_rep (new QTMWindow (0), "popup", _quit), helper (this), prompt (NULL), full_screen (false) { type = texmacs_widget; main_widget = concrete (::glue_widget (true, true, 1, 1)); // decode mask visibility[0] = (mask & 1) == 1; // header visibility[1] = (mask & 2) == 2; // main visibility[2] = (mask & 4) == 4; // mode visibility[3] = (mask & 8) == 8; // focus visibility[4] = (mask & 16) == 16; // user visibility[5] = (mask & 32) == 32; // footer visibility[6] = (mask & 64) == 64; // side tools #0 visibility[7] = (mask & 128) == 128; // bottom tools // general setup for main window QMainWindow* mw= mainwindow (); mw->setStyle (qtmstyle ()); mw->menuBar()->setStyle (qtmstyle ()); // there is a bug in the early implementation of toolbars in Qt 4.6 // which has been fixed in 4.6.2 (at least) // this is why we change dimension of icons #if (defined(Q_WS_MAC)&&(QT_VERSION>=QT_VERSION_CHECK(4,6,0))&&(QT_VERSION<QT_VERSION_CHECK(4,6,2))) mw->setIconSize (QSize (22, 30)); #else mw->setIconSize (QSize (17, 17)); #endif mw->setFocusPolicy (Qt::NoFocus); // status bar QStatusBar* bar= new QStatusBar(mw); leftLabel= new QLabel (qt_translate ("Welcome to TeXmacs"), mw); rightLabel= new QLabel (qt_translate ("Booting"), mw); leftLabel->setFrameStyle (QFrame::NoFrame); rightLabel->setFrameStyle (QFrame::NoFrame); bar->addWidget (leftLabel, 1); bar->addPermanentWidget (rightLabel); bar->setStyle (qtmstyle ()); // NOTE (mg): the following setMinimumWidth command disable automatic // enlarging of the status bar and consequently of the main window due to // long messages in the left label. I found this strange solution here // http://www.archivum.info/[email protected]/2007-05/01453/Re:-QStatusBar-size.html // The solution if due to Martin Petricek. He adds: // The docs says: If minimumSize() is set, the minimum size hint will be ignored. // Probably the minimum size hint was size of the lengthy message and // internal layout was enlarging the satusbar and the main window // Maybe the notice about QLayout that is at minimumSizeHint should be // also at minimumSize, didn't notice it first time and spend lot of time // trying to figure this out :) bar->setMinimumWidth (2); mw->setStatusBar (bar); // toolbars mainToolBar = new QToolBar ("main toolbar", mw); modeToolBar = new QToolBar ("mode toolbar", mw); focusToolBar = new QToolBar ("focus toolbar", mw); userToolBar = new QToolBar ("user toolbar", mw); bottomTools = new QDockWidget ("bottom tools", mw); sideTools = new QDockWidget ("side tools", 0); // HACK: Wrap the dock in a "fake" window widget (last parameter = true) to // have clicks report the right position. static int cnt=0; string dock_name = "dock:" * as_string(cnt++); dock_window_widget = tm_new<qt_window_widget_rep> (sideTools, dock_name, command(), true); mainToolBar->setStyle (qtmstyle ()); modeToolBar->setStyle (qtmstyle ()); focusToolBar->setStyle (qtmstyle ()); userToolBar->setStyle (qtmstyle ()); sideTools->setStyle (qtmstyle ()); bottomTools->setStyle (qtmstyle ()); { // set proper sizes for icons QImage *pxm = xpm_image ("tm_new.xpm"); QSize sz = (pxm ? pxm->size() : QSize (24, 24)); tweak_iconbar_size (sz); mainToolBar->setIconSize (sz); pxm = xpm_image ("tm_section.xpm"); sz = (pxm ? pxm->size() : QSize (20, 20)); tweak_iconbar_size (sz); modeToolBar->setIconSize (sz); pxm = xpm_image ("tm_add.xpm"); sz = (pxm ? pxm->size() : QSize (16, 16)); tweak_iconbar_size (sz); focusToolBar->setIconSize (sz); } QWidget *cw= new QWidget(); cw->setObjectName("central widget"); // this is important for styling toolbars. // The main layout QVBoxLayout *bl = new QVBoxLayout (cw); bl->setContentsMargins (0, 1, 0, 0); bl->setSpacing (0); cw->setLayout (bl); QWidget* q = main_widget->as_qwidget(); // force creation of QWidget q->setParent (qwid); // q->layout()->removeWidget(q) will reset the parent to this bl->addWidget (q); mw->setCentralWidget (cw); #ifdef UNIFIED_TOOLBAR mw->setUnifiedTitleAndToolBarOnMac(true); //WARNING: dumbToolBar is the toolbar installed on the top area of the //main widget which is then unified in the title bar. //to overcome some limitations of the unified toolbar implementation we //install the real toolbars as widgets in this toolbar. dumbToolBar = mw->addToolBar("dumb toolbar"); dumbToolBar->setMinimumHeight(30); //these are the actions related to the various toolbars to be installed in //the dumb toolbar. mainToolBarAction = dumbToolBar->addWidget(mainToolBar); modeToolBarAction = NULL; // A ruler rulerWidget = new QWidget(cw); rulerWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); rulerWidget->setMinimumHeight(1); rulerWidget->setBackgroundRole(QPalette::Mid); // FIXME: how to use 112 (active) and 146 (passive) rulerWidget->setVisible(false); rulerWidget->setAutoFillBackground(true); // rulerWidget = new QLabel("pippo", cw); // A second ruler (this one always visible) to separate from the canvas. QWidget* r2 = new QWidget(mw); r2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); r2->setMinimumHeight(1); r2->setBackgroundRole(QPalette::Mid); r2->setVisible(true); r2->setAutoFillBackground(true); bl->insertWidget(0, modeToolBar); bl->insertWidget(1, rulerWidget); bl->insertWidget(2, focusToolBar); bl->insertWidget(3, userToolBar); bl->insertWidget(5, r2); //mw->setContentsMargins (-2, -2, -2, -2); // Why this? bar->setContentsMargins (0, 1, 0, 1); #else mw->addToolBar (mainToolBar); mw->addToolBarBreak (); mw->addToolBar (modeToolBar); mw->addToolBarBreak (); mw->addToolBar (focusToolBar); mw->addToolBarBreak (); mw->addToolBar (userToolBar); mw->addToolBarBreak (); #endif sideTools->setAllowedAreas (Qt::AllDockWidgetAreas); sideTools->setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); sideTools->setFloating (false); mw->addDockWidget (Qt::RightDockWidgetArea, sideTools); bottomTools->setAllowedAreas (Qt::BottomDockWidgetArea); bottomTools->setFeatures (QDockWidget::NoDockWidgetFeatures); bottomTools->setFloating (false); bottomTools->setTitleBarWidget (new QWidget()); // Disables title bar bottomTools->setMinimumHeight (10); // Avoids warning bottomTools->setContentsMargins (3, 6, 3, -2); // Hacks hacks hacks... :( mw->addDockWidget (Qt::BottomDockWidgetArea, bottomTools); // FIXME? add DockWidgetClosable and connect the close signal // to the scheme code // QObject::connect(sideDock, SIGNAL(closeEvent()), // someHelper, SLOT(call_scheme_hide_side_tools())); // handles visibility // at this point all the toolbars are empty so we avoid showing them // same for the menu bar if we are not on the Mac (where we do not have // other options) mainToolBar->setVisible (false); modeToolBar->setVisible (false); focusToolBar->setVisible (false); userToolBar->setVisible (false); sideTools->setVisible (false); bottomTools->setVisible (false); mainwindow()->statusBar()->setVisible (true); #ifndef Q_WS_MAC mainwindow()->menuBar()->setVisible (false); #endif }
void qt_tm_widget_rep::write (slot s, blackbox index, widget w) { if (DEBUG_QT_WIDGETS) debug_widgets << "qt_tm_widget_rep::write " << slot_name (s) << LF; switch (s) { // Widget w is usually a qt_simple_widget_rep, with a QTMWidget as // underlying widget. We must discard the current main_widget and // display the new. But while switching buffers the widget w is a // glue_widget, so we may not just use canvas() everywhere. case SLOT_SCROLLABLE: { check_type_void (index, s); QWidget* q = main_widget->qwid; q->hide(); QLayout* l = centralwidget()->layout(); l->removeWidget(q); q = concrete(w)->as_qwidget(); // force creation of the new QWidget l->addWidget(q); /* " When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed " */ main_widget = concrete (w); // canvas() now returns the new QTMWidget (or 0) if (scrollarea()) // Fix size to draw margins around. scrollarea()->surface()->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); send_keyboard_focus (abstract (main_widget)); } break; case SLOT_MAIN_MENU: check_type_void (index, s); { waiting_main_menu_widget = concrete (w); if (menu_count <= 0) install_main_menu(); else if (!contains (waiting_widgets, this)) // menu interaction ongoing, postpone new menu installation until done waiting_widgets << this; } break; case SLOT_MAIN_ICONS: check_type_void (index, s); { main_icons_widget = concrete (w); QMenu* m = main_icons_widget->get_qmenu(); if (m) { replaceButtons (mainToolBar, m); update_visibility(); } } break; case SLOT_MODE_ICONS: check_type_void (index, s); { mode_icons_widget = concrete (w); QMenu* m = mode_icons_widget->get_qmenu(); if (m) { replaceButtons (modeToolBar, m); update_visibility(); } } break; case SLOT_FOCUS_ICONS: check_type_void (index, s); { focus_icons_widget = concrete (w); QMenu* m = focus_icons_widget->get_qmenu(); if (m) { replaceButtons (focusToolBar, m); update_visibility(); } } break; case SLOT_USER_ICONS: check_type_void (index, s); { user_icons_widget = concrete (w); QMenu* m = user_icons_widget->get_qmenu(); if (m) { replaceButtons (userToolBar, m); update_visibility(); } } break; case SLOT_SIDE_TOOLS: check_type_void (index, s); { side_tools_widget = concrete (w); QWidget* new_qwidget = side_tools_widget->as_qwidget(); QWidget* old_qwidget = sideTools->widget(); if (old_qwidget) old_qwidget->deleteLater(); sideTools->setWidget (new_qwidget); update_visibility(); new_qwidget->show(); } break; case SLOT_BOTTOM_TOOLS: check_type_void (index, s); { bottom_tools_widget = concrete (w); QWidget* new_qwidget = bottom_tools_widget->as_qwidget(); QWidget* old_qwidget = bottomTools->widget(); if (old_qwidget) old_qwidget->deleteLater(); bottomTools->setWidget (new_qwidget); update_visibility(); new_qwidget->show(); } break; case SLOT_INTERACTIVE_PROMPT: check_type_void (index, s); int_prompt= concrete (w); break; case SLOT_INTERACTIVE_INPUT: check_type_void (index, s); int_input= concrete (w); break; default: qt_window_widget_rep::write (s, index, w); } }
/*! * A factory for a popup widget container whose contents are to be unmapped as * soon as the mouse exits the widget. This is used in @link edit_mouse.cpp @endlink * to implement a contextual menu in the canvas * @param w The widget to be placed in the popup. It will be deleted after the * mouse leaves the popup. * @return */ widget popup_widget (widget w) { return concrete(w)->make_popup_widget(); }
widget popup_window_widget (widget w, string s) { // creates an undecorated window with name s and contents w return concrete(w)->popup_window_widget (s); }
inline operator B *() const { return concrete(i); }