Пример #1
0
void PCDMgui::slotUserSelected(QString newuser){
  if(DEBUG_MODE){ qDebug() << "User selection changed:" << newuser; }
  if(newuser.isEmpty()){
    if(!simpleDESwitcher){ deSwitcher->setVisible(false); }
  }else{
    if(!simpleDESwitcher){ deSwitcher->setVisible(true); }
    //Try to load the custom user icon
    slotUserChanged(newuser);
  }
  retranslateUi();
}
Пример #2
0
void PCDMgui::createGUIfromTheme(){
  QString style;
  QString tmpIcon; //used for checking image files before loading them
  QWidget *leftscreen = 0;
  for(int i=0; i<screens.length(); i++){
    if(screens[i]->x()==0){
      leftscreen = screens[i];
    }
  }
  //Define the default icon size
  int perc = qRound(leftscreen->height()*0.035); //use 3.5% of the screen height
  defIconSize = QSize(perc,perc);
  //Set the background image
  if(DEBUG_MODE){ qDebug() << "Setting Background Image"; }
  if( currentTheme->itemIsEnabled("background") ){
    tmpIcon = currentTheme->itemIcon("background");
    if( tmpIcon.isEmpty() || !QFile::exists(tmpIcon) ){ tmpIcon = ":/images/backgroundimage.jpg"; }
    //use "border-image" instead of "background-image" to stretch rather than tile the image
    QString bgstyle = "QWidget#BGSCREEN{border-image: url(BGIMAGE) stretch;}"; 
    bgstyle.replace("BGIMAGE", tmpIcon);
    style.append(bgstyle);
  }
  //Set the application style sheet
  style.append(" "+ currentTheme->styleSheet() );
  this->setStyleSheet( style.simplified() );

  //Check for whether the desktop switcher is on the toolbar or not
  simpleDESwitcher = (currentTheme->itemValue("desktop") == "simple");
  
  //get the default translation directory
  if(DEBUG_MODE){ qDebug() << "Load Translations"; }
  translationDir = "/usr/local/share/pcbsd/i18n/";
  //Fill the translator
  m_translator = new QTranslator();
  //Create the Toolbar
  toolbar = new QToolBar();
  //Add the Toolbar to the window
  if(DEBUG_MODE){ qDebug() << "Create Toolbar"; }
    //use the theme location   
    QString tarea = currentTheme->itemValue("toolbar");
    if(tarea == "left"){
      this->addToolBar( Qt::LeftToolBarArea, toolbar ); 	    
    }else if( tarea=="top"){
      this->addToolBar( Qt::TopToolBarArea, toolbar );  	   
      toolbar->setFixedWidth(leftscreen->width());
    }else if(tarea=="right"){
      this->addToolBar( Qt::RightToolBarArea, toolbar );   	    
    }else{ //bottom is default
      this->addToolBar( Qt::BottomToolBarArea, toolbar ); 	
      toolbar->setFixedWidth(leftscreen->width());
    }
    //Set toolbar flags
    toolbar->setVisible(true);
    toolbar->setMovable(false);
    toolbar->setFloatable(false);
    toolbar->setContextMenuPolicy(Qt::PreventContextMenu); //make sure no right-click menu
    //Set the default style and icon sizes
    QString tstyle = currentTheme->itemIcon("toolbar").toLower(); //use the theme style
    if(tstyle=="textonly"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextOnly); }
    else if(tstyle=="textbesideicon"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); }
    else if(tstyle=="textundericon"){ toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); }
    else{ toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly); } //default to icon only
    
    QSize tmpsz = currentTheme->itemIconSize("toolbar");
    if(!tmpsz.isValid()){ tmpsz = defIconSize; }
    toolbar->setIconSize( tmpsz ); //use theme size
    toolbar->setFocusPolicy( Qt::NoFocus );
  //Populate the Toolbar with items (starts at leftmost/topmost)
    //----Virtual Keyboard
    if(currentTheme->itemIsEnabled("vkeyboard") ){
      if(DEBUG_MODE){ qDebug() << " - Create Virtual Keyboard Button"; }
      tmpIcon = currentTheme->itemIcon("vkeyboard");
      if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/input-keyboard.png"; }
      virtkeyboardButton = new QAction( QIcon(tmpIcon),tr("Virtual Keyboard"),this );
      toolbar->addAction(virtkeyboardButton);
      connect( virtkeyboardButton, SIGNAL(triggered()), this, SLOT(slotPushVirtKeyboard()) );
    }else{
      virtkeyboardButton = new QAction(this);
    }

    //----Locale Switcher
    if(DEBUG_MODE){ qDebug() << " - Create Locale Button"; }
    tmpIcon = currentTheme->itemIcon("locale");
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/language.png"; }
    localeButton = new QAction( QIcon(tmpIcon),tr("Locale"),this );
    toolbar->addAction(localeButton);
    connect( localeButton, SIGNAL(triggered()), this, SLOT(slotChangeLocale()) );
    
    //----Keyboard Layout Switcher
    if(DEBUG_MODE){ qDebug() << " - Create Keyboard Layout Button"; }
    tmpIcon = currentTheme->itemIcon("keyboard");
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/keyboard.png"; }
    keyboardButton = new QAction( QIcon(tmpIcon),tr("Keyboard Layout"),this );
    toolbar->addAction(keyboardButton);
    connect( keyboardButton, SIGNAL(triggered()), this, SLOT(slotChangeKeyboardLayout()) );

    //----Add a spacer
    QWidget* spacer = new QWidget();
    spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
    toolbar->addWidget(spacer);
        
    //----System Shutdown/Restart
    if(DEBUG_MODE){ qDebug() << " - Create System Button"; }
    tmpIcon = currentTheme->itemIcon("system");
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/system.png"; }
    QAction* act = new QAction( QIcon(tmpIcon),tr("System"),this );
    systemButton = new QToolButton();
    systemButton->setDefaultAction(act);
    systemMenu = new QMenu();
    toolbar->addWidget(systemButton);
    systemButton->setPopupMode( QToolButton::InstantPopup );
    systemButton->setFocusPolicy( Qt::NoFocus );
    
  //Create the grid layout
  QGridLayout* grid = new QGridLayout;
  if(DEBUG_MODE){ qDebug() << "Fill Desktop Area"; }
  //Populate the grid with items
    //----Header Image
    QLabel* header = new QLabel; 
    if( currentTheme->itemIsEnabled("header") ){
      if(DEBUG_MODE){ qDebug() << " - Create Header"; }
      tmpIcon = currentTheme->itemIcon("header");
      if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/banner.png"; }
      QPixmap tmp( tmpIcon );
      header->setPixmap( tmp.scaled( currentTheme->itemIconSize("header") ) );
      grid->addWidget( header, currentTheme->itemLocation("header","row"), \
                      currentTheme->itemLocation("header","col"), \
                      currentTheme->itemLocation("header","rowspan"), \
                      currentTheme->itemLocation("header","colspan"), Qt::AlignCenter);
    }
    
    //Username/Password/Login widget
    if(DEBUG_MODE){ qDebug() << " - Create Login Widget"; }
    loginW = new LoginWidget;
    /*loginW->setUsernames(Backend::getSystemUsers()); //add in the detected users
    QString lastUser = Backend::getLastUser();
    if(!lastUser.isEmpty()){ //set the previously used user
    	loginW->setCurrentUser(lastUser); 
    }*/
    //Set Icons from theme
    tmpIcon = currentTheme->itemIcon("login");
    tmpsz = currentTheme->itemIconSize("login");
    if(!tmpsz.isValid()){ tmpsz = defIconSize; }
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/next.png"; }
    loginW->changeButtonIcon("login",tmpIcon, tmpsz);
    tmpIcon = currentTheme->itemIcon("anonlogin");
    tmpsz = currentTheme->itemIconSize("login");
    if(!tmpsz.isValid()){ tmpsz = defIconSize; }
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/next-stealth.png"; }
    loginW->changeButtonIcon("anonlogin", tmpIcon, tmpsz);
    tmpIcon = currentTheme->itemIcon("user");
    slotUserChanged(loginW->currentUsername()); //Make sure that we have the correct user icon
    tmpIcon = currentTheme->itemIcon("password");
    tmpsz = currentTheme->itemIconSize("password");
    if(!tmpsz.isValid()){ tmpsz = defIconSize; }
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/password.png"; }
    loginW->changeButtonIcon("pwview",tmpIcon, tmpsz);
    tmpIcon = currentTheme->itemIcon("encdevice");
    tmpsz = currentTheme->itemIconSize("device");
    if(!tmpsz.isValid()){ tmpsz = defIconSize; }
    if(!QFile::exists(tmpIcon) || tmpIcon.isEmpty() ){ tmpIcon=":/images/usbdevice.png"; }
    loginW->changeButtonIcon("device", tmpIcon, tmpsz);
    //Enable/disable the password view functionality
    loginW->allowPasswordView( Config::allowPasswordView() );
    loginW->allowUserSelection( Config::allowUserSelection() );
    loginW->allowAnonLogin( Config::allowAnonLogin() );
    //Add item to the grid
    grid->addWidget( loginW, currentTheme->itemLocation("login","row"), \
                      currentTheme->itemLocation("login","col"), \
                      currentTheme->itemLocation("login","rowspan"), \
                      currentTheme->itemLocation("login","colspan"), Qt::AlignCenter);
    //Connect the signals/slots
    connect(loginW,SIGNAL(loginRequested(QString,QString)),this,SLOT(slotStartLogin(QString,QString)));
    connect(loginW,SIGNAL(escapePressed()),this,SLOT(slotShutdownComputer()));
    connect(loginW,SIGNAL(UserSelected(QString)), this, SLOT(slotUserSelected(QString)) );
    connect(loginW,SIGNAL(UserChanged(QString)), this, SLOT(slotUserChanged(QString)) );
    
    //----Desktop Environment Switcher
    if(simpleDESwitcher){
      tmpsz = currentTheme->itemIconSize("desktop");
      if(!tmpsz.isValid()){ tmpsz = defIconSize; }
      loginW->setDesktopIconSize(tmpsz);
    }else{
      if(DEBUG_MODE){ qDebug() << " - Create DE Switcher"; }
      //Create the switcher
      deSwitcher = new FancySwitcher(this, !currentTheme->itemIsVertical("desktop") );
      tmpsz = currentTheme->itemIconSize("desktop");
      if(!tmpsz.isValid()){ tmpsz = defIconSize; }
      deSwitcher->setIconSize(tmpsz.height());
      tmpIcon = currentTheme->itemIcon("nextde");
      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("forward", tmpIcon); }
      tmpIcon = currentTheme->itemIcon("previousde");
      if( !tmpIcon.isEmpty() && QFile::exists(tmpIcon) ){ deSwitcher->changeButtonIcon("back", tmpIcon); }
      //Figure out if we need to smooth out the animation
      deSwitcher->setNumberAnimationFrames("4"); 
      //NOTE: A transparent widget background slows the full animation to a crawl with a stretched background image

      grid->addWidget( deSwitcher, currentTheme->itemLocation("desktop","row"), \
                      currentTheme->itemLocation("desktop","col"), \
                      currentTheme->itemLocation("desktop","rowspan"), \
                      currentTheme->itemLocation("desktop","colspan"), Qt::AlignCenter);
    }
    //----WINDOW SPACERS
    QStringList spacers = currentTheme->getSpacers();
    for(int i=0; i<spacers.length(); i++){
      bool isVertical = (spacers[i].section("::",0,0) == "true");
      int row = spacers[i].section("::",1,1).toInt();
      int col = spacers[i].section("::",2,2).toInt();
      //qDebug() << "Add Spacer:" << isVertical << row << col;
      if(isVertical){
        grid->setRowStretch(row,1);
      }else{ //horizontal
        grid->setColumnStretch(col,1);
      }
    }

  //Connect the grid to the leftmost screen widget
  leftscreen->setLayout(grid);
    
  //Now translate the UI and set all the text
  if(DEBUG_MODE){ qDebug() << " - Fill GUI with data"; }
  //retranslateUi();
  LoadAvailableUsers(); //Note: this is the first time it is run
  if(DEBUG_MODE){ qDebug() << " - Translate GUI"; }
  retranslateUi();
  if(DEBUG_MODE){ qDebug() << "Done with initialization"; }

}
Пример #3
0
void KMJobViewer::initActions()
{
    // job actions
    KAction	*hact = new KAction(i18n("&Hold"),"stop",0,this,SLOT(slotHold()),actionCollection(),"job_hold");
    KAction	*ract = new KAction(i18n("&Resume"),"run",0,this,SLOT(slotResume()),actionCollection(),"job_resume");
    KAction	*dact = new KAction(i18n("Remo&ve"),"edittrash",Qt::Key_Delete,this,SLOT(slotRemove()),actionCollection(),"job_remove");
    KAction *sact = new KAction(i18n("Res&tart"),"redo",0,this,SLOT(slotRestart()),actionCollection(),"job_restart");
    KActionMenu *mact = new KActionMenu(i18n("&Move to Printer"),"fileprint",actionCollection(),"job_move");
    mact->setDelayed(false);
    connect(mact->popupMenu(),SIGNAL(activated(int)),SLOT(slotMove(int)));
    connect(mact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
    connect(mact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
    connect(mact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowMoveMenu()));
    KToggleAction	*tact = new KToggleAction(i18n("&Toggle Completed Jobs"),"history",0,actionCollection(),"view_completed");
    tact->setEnabled(m_manager->actions() & KMJob::ShowCompleted);
    connect(tact,SIGNAL(toggled(bool)),SLOT(slotShowCompleted(bool)));
    KToggleAction	*uact = new KToggleAction(i18n("Show Only User Jobs"), "personal", 0, actionCollection(), "view_user_jobs");
    uact->setCheckedState(KGuiItem(i18n("Hide Only User Jobs"),"personal"));
    connect(uact, SIGNAL(toggled(bool)), SLOT(slotUserOnly(bool)));
    m_userfield = new QLineEdit(0);
    m_userfield->setText(getenv("USER"));
    connect(m_userfield, SIGNAL(returnPressed()), SLOT(slotUserChanged()));
    connect(uact, SIGNAL(toggled(bool)), m_userfield, SLOT(setEnabled(bool)));
    m_userfield->setEnabled(false);
    m_userfield->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    KWidgetAction	*ufact = new KWidgetAction(m_userfield, i18n("User Name"), 0, 0, 0, actionCollection(), "view_username");

    if (!m_pop)
    {
        m_pop = new QPopupMenu(this);
        connect(m_pop,SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
        connect(m_pop,SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
        hact->plug(m_pop);
        ract->plug(m_pop);
        m_pop->insertSeparator();
        dact->plug(m_pop);
        mact->plug(m_pop);
        m_pop->insertSeparator();
        sact->plug(m_pop);
    }

    // Filter actions
    KActionMenu	*fact = new KActionMenu(i18n("&Select Printer"), "kdeprint_printer", actionCollection(), "filter_modify");
    fact->setDelayed(false);
    connect(fact->popupMenu(),SIGNAL(activated(int)),SLOT(slotPrinterSelected(int)));
    connect(fact->popupMenu(),SIGNAL(aboutToShow()),KMTimer::self(),SLOT(hold()));
    connect(fact->popupMenu(),SIGNAL(aboutToHide()),KMTimer::self(),SLOT(release()));
    connect(fact->popupMenu(),SIGNAL(aboutToShow()),SLOT(slotShowPrinterMenu()));

    if (!m_standalone)
    {
        KToolBar	*toolbar = toolBar();
        hact->plug(toolbar);
        ract->plug(toolbar);
        toolbar->insertSeparator();
        dact->plug(toolbar);
        mact->plug(toolbar);
        toolbar->insertSeparator();
        sact->plug(toolbar);
        toolbar->insertSeparator();
        tact->plug(toolbar);
        uact->plug(toolbar);
        ufact->plug(toolbar);
    }
    else
    {   // stand-alone application
        KStdAction::quit(kapp,SLOT(quit()),actionCollection());
        KStdAction::close(this,SLOT(slotClose()),actionCollection());
        KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection());

        // refresh action
        new KAction(i18n("Refresh"),"reload",0,this,SLOT(slotRefresh()),actionCollection(),"refresh");

        // create status bar
        KStatusBar	*statusbar = statusBar();
        m_stickybox = new QCheckBox( i18n( "Keep window permanent" ), statusbar );
        statusbar->addWidget( m_stickybox, 1, false );
        statusbar->insertItem(" " + i18n("Max.: %1").arg(i18n("Unlimited"))+ " ", 0, 0, true);
        statusbar->setItemFixed(0);
        updateStatusBar();

        createGUI();
    }

    loadPluginActions();
    slotSelectionChanged();
}