コード例 #1
0
ファイル: karaScreen.cpp プロジェクト: karawin/karaClass
// Draw all status if modified
void TStBar::Refresh()
{
  for (uint16_t i = 0; i<MAXSTATUS; i++)
  if (Status[i] != NULL)
    if (Status[i]->Modified)
      reDraw(i);
}
コード例 #2
0
ファイル: previewview.cpp プロジェクト: RISK46kaf/Practise
void PreviewView::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event)
    this->fitInView(scene->itemsBoundingRect(),Qt::KeepAspectRatio);
    QGraphicsView::resizeEvent(event);
    reDraw();
}
コード例 #3
0
ファイル: MainWindow.cpp プロジェクト: BeepBoopBop/BeepHive
void MainWindow::newEnvironmentCreated(){
  EnvironmentObject tempEnvironmentObject(newEnvironment->getX(),
                                          newEnvironment->getY(),
                                          newEnvironment->getWidth(),
                                          newEnvironment->getHeight(),
                                          newEnvironment->getSource());
  environmentObjects.push_back(tempEnvironmentObject);
  reDraw();
}
コード例 #4
0
ファイル: MainWindow.cpp プロジェクト: BeepBoopBop/BeepHive
//******************************************
//                  SLOTS                  *
//******************************************
void MainWindow::timeToStep(){
  if(!started) return;
  qDebug() << "Stepping\n";
  mpiWaitForUpdates();

  //tell all beeps to step
  if(scene) delete scene;
  scene = NULL;
  reDraw();
}
コード例 #5
0
ファイル: Hyperbola.cpp プロジェクト: dinesh1994/GraphicsLab
void reset(HWND hwnd)
{
    gDrawData.centre.x = gDrawData.centre.y = 0;

    gDrawData.drawMode = READY_MODE;

    PatBlt(gDrawData.hdcMem, 0, 0, gDrawData.maxBoundary.cx,
           gDrawData.maxBoundary.cy, PATCOPY);

    reDraw(hwnd);
    setupMenus(hwnd);
}
コード例 #6
0
ファイル: MainWindow.cpp プロジェクト: BeepBoopBop/BeepHive
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);

  newDebug = NULL;
  newAgent = NULL;
  newEnvironment = NULL;
  newBeep = NULL;

  started = false;
  paused = false;

  scene = new QGraphicsScene(this);
  ui->graphicsView->setScene(scene);
  setCentralWidget(ui->graphicsView);

  //automatically trigger updates for now
  timer = new QTimer(this);
  connect(timer, SIGNAL(timeout()), this, SLOT(timeToStep()));
  timer->start(10);

  //connect menus to their corresponding slots
  connect(ui->actionStep,SIGNAL(triggered()),this,SLOT(timeToStep()));
  connect(ui->actionAgent_2, SIGNAL(triggered()), this, SLOT(createNewAgentWindow()));
  connect(ui->actionAdd_Environment, SIGNAL(triggered()), this, SLOT(createNewEnvironmentWindow()));
  connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(startSimulation()));
  connect(ui->actionCreate_New_Beep, SIGNAL(triggered()), this, SLOT(createNewBeepTypeWindow()));
  connect(ui->actionPause, SIGNAL(triggered()), this, SLOT(pauseSimulation()));
  connect(ui->actionContinue, SIGNAL(triggered()), this, SLOT(unPauseSimulation()));


  /*for(int i = 5; i < 26; i++)
    for(int j = 15; j < 26; j++)
      pointTemps.push_back(std::make_pair (std::make_pair (i,j), 100));*/

  /*QGraphicsEllipseItem *tempEllipse = new QGraphicsEllipseItem();
  for(unsigned i = 0; i < 2; i++){
    Robot tempRobot = Robot();
    tempRobot.setBody(tempEllipse);
    robots.push_back(tempRobot);
  }

  for(unsigned i = 0; i<robots.size(); i++){
    robots[i].updateDrawPosition(scene);
  }*/
  reDraw();
}
コード例 #7
0
void AllianceAreaPopupView::refreshShowNode(bool isDrag/* = true*/){
    CCPoint pt = getMovePoint();
    if(!pt.equals(ccp(0, 0))){
        m_picNode->setPosition(m_picNode->getPosition() + pt);
        if(isDrag){
            float maxMove = 15;
            auto moveDis = sqrt(pow(pt.x, 2) + pow(pt.y, 2));
            if(moveDis > maxMove){
                pt = pt * (maxMove * 1.0f / moveDis);
            }
            
            getMapNode()->setPosition(getMapNode()->getPosition() + pt);
            reDraw(NULL);
        }else{
            auto seque = CCSequence::create(CCMoveTo::create(0.2, getMapNode()->getPosition() + pt)
                                            , CCCallFuncN::create(this, callfuncN_selector(AllianceAreaPopupView::reDraw))
                                            , NULL
                                            );
            getMapNode()->runAction(seque);
        }
    }else{
        reDraw(NULL);
    }
}
コード例 #8
0
void FriendListWidget::onGroupchatPositionChanged(bool top)
{
    groupsOnTop = top;

    if (mode != Name)
        return;

    listLayout->removeItem(groupLayout.getLayout());

    if (top)
        listLayout->insertLayout(0, groupLayout.getLayout());
    else
        listLayout->insertLayout(1, groupLayout.getLayout());

    reDraw();
}
コード例 #9
0
ファイル: TFTButton.cpp プロジェクト: Nand-e/STM32-Watering
void Button::updateButtonState ( uint16_t x, uint16_t y, bool press ) {
    bool oldpressed = pressed;
	if (press) {
		if (x > x1 && x < (x1 + w) && y > y1 && y < (y1 + h)) {
			pressed = true;
			lastpressed = millis();
		}
	}

	if (millis() - lastpressed > 200) pressed = false;

	if (oldpressed != pressed) {										// Button changed
		reDraw();
		if (handler != 0 ) handler->callBack1(pressed, ID);
		return;
	}
	if (pressed && handler != 0)  handler->callBack2(pressed, ID);     // continouse pressing 
} 
コード例 #10
0
ファイル: dualSeg.c プロジェクト: HoboJ/avr
int main ( void )
{
    DDRD = 0xFF;
    DDRB = 0xFF;

    int hexVals[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xf8,0x80,0x98,0xA3,0x83,0xA7,0xA1,0x86,0x8E};

    while ( 1 )
    {
        int j = 0;

        for ( int i = 0; i <= 15; i++ )
        {
            j = i + 1;

            if ( j == 16 )
                j = 0;

            reDraw ( i, j, hexVals );
        }
    }
}
コード例 #11
0
ファイル: Hyperbola.cpp プロジェクト: dinesh1994/GraphicsLab
void addPoint(HWND hwnd, int x, int y)
{
    switch (gDrawData.drawMode)
    {
    case DRAW_MODE:
        /* the coordinates of the centre is stored
           and the Hyperbola is drawn */
        SelectObject(gDrawData.hdcMem, gDrawData.hDrawPen);
        drawPoint(x, y);
        gDrawData.centre.x = x;
        gDrawData.centre.y = y;
        drawHyperbola();
        setDrawMode(DRAWN_MODE, hwnd);
        reDraw(hwnd);
        break;
    case DRAWN_MODE:
        MessageBox(hwnd,
                   "Hyperbola already drawn, now you can clear the area",
                   "Warning", MB_OK);
        break;
    default:
        break;
    }
}
コード例 #12
0
ファイル: friendlistwidget.cpp プロジェクト: initramfs/qTox
void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
{
    CircleWidget* circleWidget = createCircleWidget();
    if (circleWidget != nullptr) {
        if (friendWidget != nullptr) {
            Friend* f = FriendList::findFriend(friendWidget->friendId);
            ToxPk toxPk = f->getPublicKey();
            int circleId = Settings::getInstance().getFriendCircleID(toxPk);
            CircleWidget* circleOriginal = CircleWidget::getFromID(circleId);

            circleWidget->addFriendWidget(friendWidget, f->getStatus());
            circleWidget->setExpanded(true);

            if (circleOriginal != nullptr)
                Widget::getInstance()->searchCircle(circleOriginal);
        }

        Widget::getInstance()->searchCircle(circleWidget);

        if (window()->isActiveWindow())
            circleWidget->editName();
    }
    reDraw();
}
コード例 #13
0
void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
{
    CircleWidget* circleWidget = createCircleWidget();
    if (circleWidget != nullptr)
    {
        if (friendWidget != nullptr)
        {
            CircleWidget* circleOriginal = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId()));

            circleWidget->addFriendWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus());
            circleWidget->setExpanded(true);

            if (circleOriginal != nullptr)
                Widget::getInstance()->searchCircle(circleOriginal);

        }

        Widget::getInstance()->searchCircle(circleWidget);

        if (window()->isActiveWindow())
            circleWidget->editName();
    }
    reDraw();
}
コード例 #14
0
//Draws the 3D scene
void drawScene() {
	int i;
	//Clear information from last draw
	glClear(GL_COLOR_BUFFER_BIT);
	
	glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
	glLoadIdentity(); //Reset the drawing perspective
	
	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_QUADS);
	glVertex3f(-2.0f,-2.0f,-5.0f);
	glVertex3f(-2.0f,2.0f,-5.0f);
	glVertex3f(2.0f,2.0f,-5.0f);
	glVertex3f(2.0f,-2.0f,-5.0f);
	glEnd();//outer black quad
	
	glColor3f(0.99f, 0.84f, 0.61f);
	glBegin(GL_QUADS);
	glVertex3f(-1.8f,-1.8f,-5.0f);
	glVertex3f(-1.8f,1.8f,-5.0f);
	glVertex3f(1.8f,1.8f,-5.0f);
	glVertex3f(1.8f,-1.8f,-5.0f);
	glEnd();//board 
	
	glColor3f(0.0f,0.0f,0.0f);
	drawDisc(0.0f,0.0f,0.42f,1000);
	glColor3f(0.99f, 0.84f, 0.61f);
	drawDisc(0.0f,0.0f,0.40f,1000);
	glColor3f(0.0f, 0.0f, 0.0f);
	drawDisc(0.0f,0.0f,0.38f,1000);
	glColor3f(0.99f, 0.84f, 0.61f);
	drawDisc(0.0f,0.0f,0.36f,1000);//central circle
	
	glColor3f(0.0f,0.0f,0.0f);
	drawDisc(0.0f,0.0f,0.08f,1000);
	glColor3f(1.0f,0.0f,0.0f);
	drawDisc(0.0f,0.0f,0.06f,1000);//central disc
	
	
	
	drawCircle(0.0f,0.0f,0.08f);
	drawTri();//for stars
	
	for(i=0;i<4;i++){
	//symmetric codes
	glColor3f(0.52f, 0.37f, 0.26f);
	drawDisc(1.69f, 1.69f, 0.11f,1000);//holes
	
	//drawArc(0.6f,0.6f,0.2121f);
	glColor3f(0.0f, 0.0f, 0.0f);
	//drawArc(0.6f,0.6f,0.2121f);
	glBegin(GL_LINE_STRIP);
	glVertex3f(0.45f,0.45f,-5.0f);//45 degree line
	glVertex3f(1.4f,1.4f,-5.0f);
	glBegin(GL_LINE_STRIP);
	glVertex3f(1.4f,1.4f,-5.0f);//arrows
	glVertex3f(1.36f,1.4f,-5.0f);
	glVertex3f(1.4f,1.4f,-5.0f);//arrows
	glVertex3f(1.4f,1.36f,-5.0f);
	glEnd();
	drawArc(0.6f,0.6f,0.2121f);
		
	glColor3f(0.0f,0.0f,0.0f);
	glBegin(GL_QUADS);//base line
	glVertex3f(1.1f, 1.2f, -5.0f);
	glVertex3f(1.1f, 1.21f, -5.0f);
	glVertex3f(-1.1f, 1.21f, -5.0f);
	glVertex3f(-1.1f, 1.2f, -5.0f);
	
	glVertex3f(1.1f, 1.35f, -5.0f);
	glVertex3f(1.1f, 1.33f, -5.0f);
	glVertex3f(-1.1f, 1.33f, -5.0f);
	glVertex3f(-1.1f, 1.35f, -5.0f);
	glEnd();
	
	glColor3f(1.0f, 0.0f, 0.0f);//base line circles
	drawDisc(1.1f, 1.275f, 0.075f,1000);
	drawDisc(-1.1f, 1.275f, 0.075f,1000);
	glColor3f(0.0f,0.0f,0.0f);
	drawCircle(1.1f, 1.275f, 0.075f);
	drawCircle(-1.1f, 1.275f, 0.075f);
	glRotatef(90.0f,0.0f,0.0f,1.0f);
	}
	reDraw();
	glutSwapBuffers(); //Send the 3D scene to the screen
}
コード例 #15
0
layoutEditPreviewDialog::layoutEditPreviewDialog(NineMLLayout * inSrcNineMLLayout, glConnectionWidget * glConn, QWidget *parent) :
    QDialog(parent)
{

    srcNineMLLayout = inSrcNineMLLayout;
    glView = glConn;
    QObject::connect(this, SIGNAL(drawLayout(vector<loc>)), glView, SLOT(drawLocations(vector<loc>)));

    this->setModal(true);
    this->setMinimumSize(200, 400);
    this->setWindowTitle("Preview layout");
    //this->setWindowIcon();

    // add the main layout
    this->setLayout(new QVBoxLayout);
    this->layout()->setContentsMargins(0,0,0,0);

    // make the dialog scrollable
    this->layout()->addWidget(new QScrollArea);
    QWidget * content = new QWidget;
    ((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidget(content);
    ((QScrollArea *) this->layout()->itemAt(0)->widget())->setWidgetResizable(true);
    content->setLayout(new QFormLayout);
    QFormLayout * contentLayout = (QFormLayout *) content->layout();

    QSpinBox * numNeurons = new QSpinBox;
    numNeurons->setRange(1, 20000000);
    numNeurons->setProperty("name", "numNeurons");
    numNeurons->setValue(99.0);
    QObject::connect(numNeurons, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));


    contentLayout->addRow("Number of neurons:", numNeurons);


    // start adding the items
    if (srcNineMLLayout->ParameterList.size() > 1) {
        contentLayout->addRow("<b>Parameters</b>", new QLabel(""));
    }

    // add the parameters
    for (uint i = 0; i < srcNineMLLayout->ParameterList.size(); ++i) {

        if (srcNineMLLayout->ParameterList[i]->name != "numNeurons") {
            // add to main layout
            QDoubleSpinBox * value = new QDoubleSpinBox;
            value->setRange(-200000, 200000);
            value->setSingleStep(0.1);
            value->setDecimals(3);
            value->setValue(1.0);
            value->setProperty("name", srcNineMLLayout->ParameterList[i]->name);
            QObject::connect(value, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));
            contentLayout->addRow(srcNineMLLayout->ParameterList[i]->name + ":", value);
        }

    }

    if (srcNineMLLayout->StateVariableList.size() > 3) {
        contentLayout->addRow("<b>State variables</b>", new QLabel(""));
    }

    // add the state vars
    for (uint i = 0; i < srcNineMLLayout->StateVariableList.size(); ++i) {

        if (srcNineMLLayout->StateVariableList[i]->name != "x" && srcNineMLLayout->StateVariableList[i]->name != "y" && srcNineMLLayout->StateVariableList[i]->name != "z") {
            // add to main layout
            QDoubleSpinBox * value = new QDoubleSpinBox;
            value->setRange(-200000, 200000);
            value->setSingleStep(0.1);
            value->setDecimals(3);
            value->setValue(1.0);
            value->setProperty("name", srcNineMLLayout->StateVariableList[i]->name);
            QObject::connect(value, SIGNAL(valueChanged(QString)), this, SLOT(reDraw(QString)));
            contentLayout->addRow(srcNineMLLayout->StateVariableList[i]->name + ":", value);
        }

    }

    contentLayoutRef = contentLayout;

    // force a redraw!
    numNeurons->setValue(100.0);
}
コード例 #16
0
ファイル: guientity_txt.c プロジェクト: BaoYu0721/xv6_gui
uint txt_setAttr(uint elem_, int attr, void *val)
{
    txt *elem=(txt*)elem_;
    int i,j,k,l;
    int qq,ww,ee,rr;
    uint u;

    switch (attr)
    {
    case GUIATTR_TXT_X:
        i=elem->ds.x;
        elem->ds.x=*((int*)val);

        qq=min(i,elem->ds.x);
        ww=elem->ds.y;
        ee=elem->ds.width+abs(elem->ds.x-i);
        rr=elem->ds.height;
        if (ee*rr<=2*elem->ds.width*elem->ds.height)
        {
            reDraw_(elem->ds.parent,qq,ww,ee,rr);
            return 0;
        }

        reDraw_(elem->ds.parent,i,elem->ds.y,elem->ds.width,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_Y:
        j=elem->ds.y;
        elem->ds.y=*((int*)val);

        qq=elem->ds.x;
        ww=min(j,elem->ds.y);
        ee=elem->ds.width;
        rr=elem->ds.height+abs(elem->ds.y-j);
        if (ee*rr<=2*elem->ds.width*elem->ds.height)
        {
            reDraw_(elem->ds.parent,qq,ww,ee,rr);
            return 0;
        }

        reDraw_(elem->ds.parent,elem->ds.x,j,elem->ds.width,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_INCX:
        i=elem->ds.x;
        elem->ds.x=(*((int*)val))+i;

        qq=min(i,elem->ds.x);
        ww=elem->ds.y;
        ee=elem->ds.width+abs(elem->ds.x-i);
        rr=elem->ds.height;
        if (ee*rr<=2*elem->ds.width*elem->ds.height)
        {
            reDraw_(elem->ds.parent,qq,ww,ee,rr);
            return 0;
        }

        reDraw_(elem->ds.parent,i,elem->ds.y,elem->ds.width,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_INCY:
        j=elem->ds.y;
        elem->ds.y=(*((int*)val))+j;

        qq=elem->ds.x;
        ww=min(j,elem->ds.y);
        ee=elem->ds.width;
        rr=elem->ds.height+abs(elem->ds.y-j);
        if (ee*rr<=2*elem->ds.width*elem->ds.height)
        {
            reDraw_(elem->ds.parent,qq,ww,ee,rr);
            return 0;
        }

        reDraw_(elem->ds.parent,elem->ds.x,j,elem->ds.width,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_WIDTH:
        if (*((uint*)val)<elem->chWidth)
            return -1;
        i=elem->ds.width;
        elem->ds.width=*((uint*)val);
        txt_adjustXY((uint)elem);
        reDraw_(elem->ds.parent,elem->ds.x,elem->ds.y,i,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_HEIGHT:
        if (*((uint*)val)<elem->ds.height)
            return -1;
        elem->ds.height=*((uint*)val);
        return 0;
    case GUIATTR_TXT_INCW:
        if (*((int*)val)+(int)elem->ds.width<(int)elem->chWidth)
            return -1;
        i=elem->ds.width;
        elem->ds.width=(*((int*)val))+i;
        txt_adjustXY((uint)elem);
        reDraw_(elem->ds.parent,elem->ds.x,elem->ds.y,i,elem->ds.height);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_INCH:
        if ((*((int*)val))<0)
            return -1;
        elem->ds.height=(*((int*)val))+elem->ds.height;
        return 0;
    case GUIATTR_TXT_FONT:
        i=initFont(val);
        return i;
    case GUIATTR_TXT_FONTIDX:
        i=*((uint*)val);
        if (i>=FONT_NUM) return -1;
        if (elem->ds.width<fontSize[i][0]) return -1;
        elem->chWidth=fontSize[i][0];
        elem->chHeight=fontSize[i][1];
        elem->chImgArray=fontArray[i];
        txt_adjustFont((uint)elem);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_STR:
        u=txt_setStr((uint)elem, (char*)val);
        return u;
    case GUIATTR_TXT_COLOR:
        elem->txtColor=*((color24*)val);
        txt_adjustColor((uint)elem);
        reDraw(&elem->ds);
        return 0;
    case GUIATTR_TXT_REFRESH:
        reDraw(elem->ds.parent);
        return 0;
    case GUIATTR_TXT_INCCURS:
        u=txt_incCursor((uint)elem);
        return u;
    case GUIATTR_TXT_DECCURS:
        u=txt_decCursor((uint)elem);
        return u;
    case GUIATTR_TXT_SETCURS:
        u=txt_setCursor((uint)elem, *(uint*)val);
        return u;
    case GUIATTR_TXT_INSERT:
        u=txt_insert((uint)elem, *(char*)val);
        return u;
    case GUIATTR_TXT_ISCHILD:
        u=txt_isChild((uint)elem, *(uint*)val);
        return u;
    case GUIATTR_TXT_INTEGRL:
        elem->ds.isIntegral=*(uchar*)val;
        return 0;
    case GUIATTR_TXT_XYWH:
        i=elem->ds.x;
        j=elem->ds.y;
        k=elem->ds.width;
        l=elem->ds.height;
        elem->ds.x=*((int*)val);
        elem->ds.y=*(((int*)val)+1);
        elem->ds.width=*(((uint*)val)+2);
        elem->ds.height=*(((uint*)val)+3);

        qq=min(i,elem->ds.x);
        ww=min(j,elem->ds.y);
        ee=elem->ds.width+abs(elem->ds.x-i);
        rr=elem->ds.height+abs(elem->ds.y-j);
        if (ee*rr<=k*l+elem->ds.width*elem->ds.height)
        {
            reDraw_(elem->ds.parent,qq,ww,ee,rr);
            return 0;
        }

        reDraw_(elem->ds.parent,i,j,k,l);
        reDraw(&elem->ds);
        return 0;
    default:
        return -1;
    }
    return 0;
}
コード例 #17
0
ファイル: friendlistwidget.cpp プロジェクト: initramfs/qTox
void FriendListWidget::setMode(Mode mode)
{
    if (this->mode == mode)
        return;

    this->mode = mode;

    if (mode == Name) {
        circleLayout = new GenericChatItemLayout;
        circleLayout->getLayout()->setSpacing(0);
        circleLayout->getLayout()->setMargin(0);

        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i) {
            addCircleWidget(i);
            CircleWidget::getFromID(i)->setVisible(false);
        }

        // Only display circles once all created to avoid artifacts.
        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
            CircleWidget::getFromID(i)->setVisible(true);

        int count = activityLayout ? activityLayout->count() : 0;
        for (int i = 0; i < count; i++) {
            QWidget* widget = activityLayout->itemAt(i)->widget();
            CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
            if (categoryWidget) {
                categoryWidget->moveFriendWidgets(this);
            } else {
                qWarning() << "Unexpected widget";
            }
        }

        listLayout->addLayout(listLayout->getLayoutOnline());
        listLayout->addLayout(listLayout->getLayoutOffline());
        listLayout->addLayout(circleLayout->getLayout());
        onGroupchatPositionChanged(groupsOnTop);

        if (activityLayout != nullptr) {
            QLayoutItem* item;
            while ((item = activityLayout->takeAt(0)) != nullptr) {
                delete item->widget();
                delete item;
            }
            delete activityLayout;
            activityLayout = nullptr;
        }

        reDraw();
    } else if (mode == Activity) {
        QLocale ql(Settings::getInstance().getTranslation());
        QDate today = QDate::currentDate();
#define COMMENT "Category for sorting friends by activity"
        // clang-format off
        const QMap<Time, QString> names {
            { Time::Today,     tr("Today",                      COMMENT) },
            { Time::Yesterday, tr("Yesterday",                  COMMENT) },
            { Time::ThisWeek,  tr("Last 7 days",                COMMENT) },
            { Time::ThisMonth, tr("This month",                 COMMENT) },
            { Time::LongAgo,   tr("Older than 6 Months",        COMMENT) },
            { Time::Never,     tr("Never",                      COMMENT) },
            { Time::Month1Ago, ql.monthName(today.addMonths(-1).month()) },
            { Time::Month2Ago, ql.monthName(today.addMonths(-2).month()) },
            { Time::Month3Ago, ql.monthName(today.addMonths(-3).month()) },
            { Time::Month4Ago, ql.monthName(today.addMonths(-4).month()) },
            { Time::Month5Ago, ql.monthName(today.addMonths(-5).month()) },
        };
// clang-format on
#undef COMMENT

        activityLayout = new QVBoxLayout();
        bool compact = Settings::getInstance().getCompactLayout();
        for (Time t : names.keys()) {
            CategoryWidget* category = new CategoryWidget(compact, this);
            category->setName(names[t]);
            activityLayout->addWidget(category);
        }

        moveFriends(listLayout->getLayoutOffline());
        moveFriends(listLayout->getLayoutOnline());
        moveFriends(circleLayout->getLayout());

        for (int i = 0; i < activityLayout->count(); ++i) {
            QWidget* widget = activityLayout->itemAt(i)->widget();
            CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
            categoryWidget->setVisible(categoryWidget->hasChatrooms());
        }

        listLayout->removeItem(listLayout->getLayoutOnline());
        listLayout->removeItem(listLayout->getLayoutOffline());

        if (circleLayout != nullptr) {
            listLayout->removeItem(circleLayout->getLayout());

            QLayoutItem* item;
            while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr) {
                delete item->widget();
                delete item;
            }
            delete circleLayout;
            circleLayout = nullptr;
        }

        listLayout->insertLayout(1, activityLayout);

        reDraw();
    }
}
コード例 #18
0
void FriendListWidget::setMode(Mode mode)
{
    if (this->mode == mode)
        return;

    this->mode = mode;

    if (mode == Name)
    {
        circleLayout = new GenericChatItemLayout;
        circleLayout->getLayout()->setSpacing(0);
        circleLayout->getLayout()->setMargin(0);

        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
        {
            addCircleWidget(i);
            CircleWidget::getFromID(i)->setVisible(false);
        }

        // Only display circles once all created to avoid artifacts.
        for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
            CircleWidget::getFromID(i)->setVisible(true);

        QList<Friend*> friendList = FriendList::getAllFriends();
        for (Friend* contact : friendList)
        {
            int circleId = Settings::getInstance().getFriendCircleID(contact->getToxId());
            addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId);
        }

        listLayout->addLayout(listLayout->getLayoutOnline());
        listLayout->addLayout(listLayout->getLayoutOffline());
        listLayout->addLayout(circleLayout->getLayout());
        onGroupchatPositionChanged(groupsOnTop);

        if (activityLayout != nullptr)
        {
            QLayoutItem* item;
            while ((item = activityLayout->takeAt(0)) != nullptr)
            {
                delete item->widget();
                delete item;
            }
            delete activityLayout;
            activityLayout = nullptr;
        }

        reDraw();
    }
    else if (mode == Activity)
    {
        activityLayout = new QVBoxLayout();

        CategoryWidget* categoryToday = new CategoryWidget(this);
        categoryToday->setObjectName("Todddd");
        categoryToday->setName(tr("Today", "Category for sorting friends by activity"));
        activityLayout->addWidget(categoryToday);

        CategoryWidget* categoryYesterday = new CategoryWidget(this);
        categoryYesterday->setName(tr("Yesterday", "Category for sorting friends by activity"));
        activityLayout->addWidget(categoryYesterday);

        CategoryWidget* categoryLastWeek = new CategoryWidget(this);
        categoryLastWeek->setName(tr("Last 7 days", "Category for sorting friends by activity"));
        activityLayout->addWidget(categoryLastWeek);

        QDate currentDate = QDate::currentDate();
        //if (last7DaysWasLastMonth())
        {
            CategoryWidget* categoryThisMonth = new CategoryWidget(this);
            categoryThisMonth->setName(tr("This month", "Category for sorting friends by activity"));
            activityLayout->addWidget(categoryThisMonth);
            categoryThisMonth->setVisible(last7DaysWasLastMonth());

            if (categoryThisMonth->isVisible())
                currentDate = currentDate.addMonths(-1);
        }

        CategoryWidget* categoryLast1Month = new CategoryWidget(this);
        categoryLast1Month->setName(QDate::longMonthName(currentDate.month()));
        activityLayout->addWidget(categoryLast1Month);

        currentDate = currentDate.addMonths(-1);
        CategoryWidget* categoryLast2Month = new CategoryWidget(this);
        categoryLast2Month->setName(QDate::longMonthName(currentDate.month()));
        activityLayout->addWidget(categoryLast2Month);

        currentDate = currentDate.addMonths(-1);
        CategoryWidget* categoryLast3Month = new CategoryWidget(this);
        categoryLast3Month->setName(QDate::longMonthName(currentDate.month()));
        activityLayout->addWidget(categoryLast3Month);

        currentDate = currentDate.addMonths(-1);
        CategoryWidget* categoryLast4Month = new CategoryWidget(this);
        categoryLast4Month->setName(QDate::longMonthName(currentDate.month()));
        activityLayout->addWidget(categoryLast4Month);

        currentDate = currentDate.addMonths(-1);
        CategoryWidget* categoryLast5Month = new CategoryWidget(this);
        categoryLast5Month->setName(QDate::longMonthName(currentDate.month()));
        activityLayout->addWidget(categoryLast5Month);

        CategoryWidget* categoryOlder = new CategoryWidget(this);
        categoryOlder->setName(tr("Older than 6 Months", "Category for sorting friends by activity"));
        activityLayout->addWidget(categoryOlder);

        CategoryWidget* categoryNever = new CategoryWidget(this);
        categoryNever->setName(tr("Unknown", "Category for sorting friends by activity"));
        activityLayout->addWidget(categoryNever);

        QList<Friend*> friendList = FriendList::getAllFriends();
        for (Friend* contact : friendList)
        {
            QDate activityDate = getDateFriend(contact);
            Time time = getTime(activityDate);
            CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
            categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
        }

        for (int i = 0; i < activityLayout->count(); ++i)
        {
            CategoryWidget* categoryWidget = dynamic_cast<CategoryWidget*>(activityLayout->itemAt(i)->widget());
            categoryWidget->setVisible(categoryWidget->hasChatrooms());
        }

        listLayout->removeItem(listLayout->getLayoutOnline());
        listLayout->removeItem(listLayout->getLayoutOffline());
        listLayout->removeItem(circleLayout->getLayout());
        listLayout->insertLayout(1, activityLayout);

        if (circleLayout != nullptr)
        {
            QLayoutItem* item;
            while ((item = circleLayout->getLayout()->takeAt(0)) != nullptr)
            {
                delete item->widget();
                delete item;
            }
            delete circleLayout;
            circleLayout = nullptr;
        }

        reDraw();
    }
}